src/network/network_gui.cpp
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6298 c30fe89622df
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
4826
63b1eb7c966b (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4774
diff changeset
     3
#ifdef ENABLE_NETWORK
5720
cc0ceeafaa55 (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: 5683
diff changeset
     4
#include "../stdafx.h"
cc0ceeafaa55 (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: 5683
diff changeset
     5
#include "../openttd.h"
cc0ceeafaa55 (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: 5683
diff changeset
     6
#include "../string.h"
cc0ceeafaa55 (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: 5683
diff changeset
     7
#include "../strings.h"
cc0ceeafaa55 (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: 5683
diff changeset
     8
#include "../table/sprites.h"
cc0ceeafaa55 (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: 5683
diff changeset
     9
#include "../date.h"
5726
8f399788f6c9 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium
parents: 5720
diff changeset
    10
#include "table/strings.h"
5720
cc0ceeafaa55 (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: 5683
diff changeset
    11
#include "../functions.h"
cc0ceeafaa55 (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: 5683
diff changeset
    12
#include "../window.h"
cc0ceeafaa55 (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: 5683
diff changeset
    13
#include "../gui.h"
cc0ceeafaa55 (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: 5683
diff changeset
    14
#include "../gfx.h"
cc0ceeafaa55 (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: 5683
diff changeset
    15
#include "../command.h"
cc0ceeafaa55 (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: 5683
diff changeset
    16
#include "../variables.h"
cc0ceeafaa55 (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: 5683
diff changeset
    17
#include "../settings.h"
cc0ceeafaa55 (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: 5683
diff changeset
    18
#include "../string.h"
cc0ceeafaa55 (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: 5683
diff changeset
    19
#include "../town.h"
cc0ceeafaa55 (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: 5683
diff changeset
    20
#include "../newgrf.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    21
#include "../helpers.hpp"
6294
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    22
#include "../fios.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    23
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    24
#include "network.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    25
#include "network_data.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    26
#include "network_client.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    27
#include "network_gui.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    28
#include "network_gamelist.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    29
#include "network_server.h"
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6263
diff changeset
    30
#include "network_udp.h"
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
d5967e472eee (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
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
    35
struct network_d {
3692
01468bf49e8b (svn r4623) - Codechange: s/byte/PlayerID/
Darkvater
parents: 3470
diff changeset
    36
	PlayerID company;        // select company in network lobby
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    37
	byte field;              // select text-field in start-server and game-listing
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    38
	NetworkGameList *server; // selected server in lobby and game-listing
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    39
	FiosItem *map;           // selected map in start-server
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
    40
};
2887
d5967e472eee (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
    41
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_d));
d5967e472eee (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
    42
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
    43
struct network_ql_d {
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    44
	network_d n;                 // see above; general stuff
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    45
	querystr_d q;                // text-input in start-server and game-listing
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    46
	NetworkGameList **sort_list; // list of games (sorted)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    47
	list_d l;                    // accompanying list-administration
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
    48
};
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    49
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_ql_d));
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    50
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    51
/* Global to remember sorting after window has been closed */
4542
24f60077489a (svn r6372) -Codechange: static, unneeded decleration in headers, superfluous header includes
Darkvater
parents: 4512
diff changeset
    52
static Listing _ng_sorting;
2887
d5967e472eee (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
    53
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4948
diff changeset
    54
static char _edit_str_buf[150];
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
    55
static bool _chat_tab_completion_active;
3470
9dc3e8d2fde1 (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
    56
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
    57
static void ShowNetworkStartServerWindow();
2887
d5967e472eee (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
    58
static void ShowNetworkLobbyWindow(NetworkGameList *ngl);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
    59
extern void SwitchMode(int new_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
static const StringID _connection_types_dropdown[] = {
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    62
	STR_NETWORK_LAN_INTERNET,
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    63
	STR_NETWORK_INTERNET_ADVERTISE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	INVALID_STRING_ID
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    67
static const StringID _lan_internet_types_dropdown[] = {
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    68
	STR_NETWORK_LAN,
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    69
	STR_NETWORK_INTERNET,
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    70
	INVALID_STRING_ID
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    71
};
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    72
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    73
static const StringID _players_dropdown[] = {
2938
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    74
	STR_NETWORK_0_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    75
	STR_NETWORK_1_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    76
	STR_NETWORK_2_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    77
	STR_NETWORK_3_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    78
	STR_NETWORK_4_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    79
	STR_NETWORK_5_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    80
	STR_NETWORK_6_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    81
	STR_NETWORK_7_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    82
	STR_NETWORK_8_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    83
	STR_NETWORK_9_PLAYERS,
78427f378daa (svn r3494) - Update several languages. Thanks all translators online atm (Bjarni, glx, MeusH, Tron, me, my sister)
Darkvater
parents: 2922
diff changeset
    84
	STR_NETWORK_10_PLAYERS,
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    85
	INVALID_STRING_ID
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    86
};
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    87
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    88
static const StringID _language_dropdown[] = {
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    89
	STR_NETWORK_LANG_ANY,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    90
	STR_NETWORK_LANG_ENGLISH,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    91
	STR_NETWORK_LANG_GERMAN,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    92
	STR_NETWORK_LANG_FRENCH,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    93
	INVALID_STRING_ID
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    94
};
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    95
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    96
enum {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    97
	NET_PRC__OFFSET_TOP_WIDGET          = 54,
2887
d5967e472eee (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
    98
	NET_PRC__OFFSET_TOP_WIDGET_COMPANY  = 52,
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    99
	NET_PRC__SIZE_OF_ROW                = 14,
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   100
};
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   101
5035
e5680cce4e67 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   102
/** Update the network new window because a new server is
e5680cce4e67 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   103
 * found on the network.
e5680cce4e67 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   104
 * @param unselect unselect the currently selected item */
897
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   105
void UpdateNetworkGameWindow(bool unselect)
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   106
{
5035
e5680cce4e67 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   107
	SendWindowMessage(WC_NETWORK_WINDOW, 0, unselect, 0, 0);
897
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   108
}
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   109
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   110
static bool _internal_sort_order; // Used for Qsort order-flipping
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   111
typedef int CDECL NGameNameSortFunction(const void*, const void*);
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   112
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   113
/** Qsort function to sort by name. */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   114
static int CDECL NGameNameSorter(const void *a, const void *b)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   115
{
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   116
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   117
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
2889
ac841003c51e (svn r3442) - Fix: Only windows has stricmp. So define strcasecmp to stricmp when using MSVC
Darkvater
parents: 2888
diff changeset
   118
	int r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   119
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   120
	return _internal_sort_order ? -r : r;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   121
}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   122
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   123
/** Qsort function to sort by the amount of clients online on a
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   124
 * server. If the two servers have the same amount, the one with the
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   125
 * higher maximum is preferred. */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   126
static int CDECL NGameClientSorter(const void *a, const void *b)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   127
{
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   128
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   129
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   130
	/* Reverse as per default we are interested in most-clients first */
4195
65070272012d (svn r5655) -Fix [SF 1424115]: Reversed arrow-sign in the multiplayer list column headers on sort by name
Darkvater
parents: 4171
diff changeset
   131
	int r = cmp1->info.clients_on - cmp2->info.clients_on;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   132
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   133
	if (r == 0) r = cmp1->info.clients_max - cmp2->info.clients_max;
2922
61cf61d25de9 (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
   134
	if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   135
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   136
	return _internal_sort_order ? -r : r;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   137
}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   138
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   139
/** Qsort function to sort by joinability. If both servers are the
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   140
 * same, prefer the non-passworded server first. */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   141
static int CDECL NGameAllowedSorter(const void *a, const void *b)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   142
{
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   143
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   144
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   145
5909
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   146
	/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   147
	int r = StrEmpty(cmp1->info.server_revision) - StrEmpty(cmp2->info.server_revision);
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   148
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   149
	/* Reverse default as we are interested in version-compatible clients first */
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   150
	if (r == 0) r = cmp2->info.version_compatible - cmp1->info.version_compatible;
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   151
	/* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   152
	if (r == 0) r = cmp2->info.compatible - cmp1->info.compatible;
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   153
	/* Passworded servers should be below unpassworded servers */
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   154
	if (r == 0) r = cmp1->info.use_password - cmp2->info.use_password;
5909
edf0f4a1f118 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5860
diff changeset
   155
	/* Finally sort on the name of the server */
2922
61cf61d25de9 (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
   156
	if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   157
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   158
	return _internal_sort_order ? -r : r;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   159
}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   160
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   161
/** (Re)build the network game list as its amount has changed because
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   162
 * an item has been added or deleted for example
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   163
 * @param ngl list_d struct that contains all necessary information for sorting */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   164
static void BuildNetworkGameList(network_ql_d *nqld)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   165
{
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   166
	NetworkGameList *ngl_temp;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   167
	uint n = 0;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   168
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   169
	if (!(nqld->l.flags & VL_REBUILD)) return;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   170
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   171
	/* Count the number of games in the list */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   172
	for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   173
	if (n == 0) return;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   174
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   175
	/* Create temporary array of games to use for listing */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   176
	free(nqld->sort_list);
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   177
	nqld->sort_list = MallocT<NetworkGameList*>(n);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   178
	if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list");
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   179
	nqld->l.list_length = n;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   180
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   181
	for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   182
		nqld->sort_list[n++] = ngl_temp;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   183
	}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   184
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   185
	/* Force resort */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   186
	nqld->l.flags &= ~VL_REBUILD;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   187
	nqld->l.flags |= VL_RESORT;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   188
}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   189
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   190
static void SortNetworkGameList(network_ql_d *nqld)
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   191
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   192
	static NGameNameSortFunction * const ngame_sorter[] = {
3860
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   193
		&NGameNameSorter,
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   194
		&NGameClientSorter,
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   195
		&NGameAllowedSorter
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   196
	};
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   197
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   198
	NetworkGameList *item;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   199
	uint i;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   200
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   201
	if (!(nqld->l.flags & VL_RESORT)) return;
3860
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   202
	if (nqld->l.list_length == 0) return;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   203
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   204
	_internal_sort_order = !!(nqld->l.flags & VL_DESC);
3860
ca80f6d89fa1 (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   205
	qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), ngame_sorter[nqld->l.sort_type]);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   206
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   207
	/* After sorting ngl->sort_list contains the sorted items. Put these back
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   208
	 * into the original list. Basically nothing has changed, we are only
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   209
	 * shuffling the ->next pointers */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   210
	_network_game_list = nqld->sort_list[0];
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   211
	for (item = _network_game_list, i = 1; i != nqld->l.list_length; i++) {
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   212
		item->next = nqld->sort_list[i];
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   213
		item = item->next;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   214
	}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   215
	item->next = NULL;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   216
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   217
	nqld->l.flags &= ~VL_RESORT;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   218
}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   219
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   220
/* Uses network_ql_d (network_d, querystr_d and list_d) WP macro */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   221
static void NetworkGameWindowWndProc(BaseWindow *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
{
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   223
	network_d *nd = &WP(w, network_ql_d).n;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   224
	list_d *ld = &WP(w, network_ql_d).l;
2887
d5967e472eee (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
   225
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   226
	switch (e->event) {
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   227
	case WE_CREATE: /* Focus input box */
2887
d5967e472eee (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
   228
		nd->field = 3;
d5967e472eee (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
   229
		nd->server = NULL;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   230
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   231
		WP(w, network_ql_d).sort_list = NULL;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   232
		ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   233
		ld->sort_type = _ng_sorting.criteria;
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   234
		break;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   235
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	case WE_PAINT: {
2887
d5967e472eee (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
   237
		const NetworkGameList *sel = nd->server;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   238
		const char *arrow = (ld->flags & VL_DESC) ? DOWNARROW : UPARROW;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   239
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   240
		if (ld->flags & VL_REBUILD) {
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   241
			BuildNetworkGameList(&WP(w, network_ql_d));
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   242
			SetVScrollCount(w, ld->list_length);
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   243
		}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   244
		if (ld->flags & VL_RESORT) SortNetworkGameList(&WP(w, network_ql_d));
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   245
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6242
diff changeset
   246
		w->SetWidgetDisabledState(17, sel == NULL);
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   247
		/* Join Button disabling conditions */
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6242
diff changeset
   248
		w->SetWidgetDisabledState(16, sel == NULL || // no Selected Server
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   249
				!sel->online || // Server offline
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   250
				sel->info.clients_on >= sel->info.clients_max || // Server full
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   251
				!sel->info.compatible); // Revision mismatch
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   252
6250
5135b200b376 (svn r8718) [cpp_gui] -Codechange: SetWindowWidgetHiddenState(), HideWindowWidget(), ShowWindowWidget() and IsWindowWidgetHidden() turned into Window methods
KUDr
parents: 6246
diff changeset
   253
		w->SetWidgetHiddenState(18, sel == NULL ||
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   254
				!sel->online ||
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   255
				sel->info.grfconfig == NULL);
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   256
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   257
		SetDParam(0, 0x00);
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   258
		SetDParam(7, _lan_internet_types_dropdown[_network_lan_internet]);
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   259
		w->DrawWidgets();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   260
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   261
		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   262
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   263
		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   264
		DrawString(210, 23, STR_NETWORK_PLAYER_NAME, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   266
		/* Sort based on widgets: name, clients, compatibility */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   267
		switch (ld->sort_type) {
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   268
			case 6 - 6: DoDrawString(arrow, w->widget[6].right - 10, 42, 0x10); break;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   269
			case 7 - 6: DoDrawString(arrow, w->widget[7].right - 10, 42, 0x10); break;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   270
			case 8 - 6: DoDrawString(arrow, w->widget[8].right - 10, 42, 0x10); break;
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   271
		}
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   272
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   273
		{ // draw list of games
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   274
			uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   275
			int32 n = 0;
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   276
			int32 pos = w->vscroll.pos;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   277
			uint max_name_width = w->widget[6].right - w->widget[6].left - 5;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   278
			const NetworkGameList *cur_item = _network_game_list;
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   279
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   280
			while (pos > 0 && cur_item != NULL) {
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   281
				pos--;
808
d4b76579b3d0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   282
				cur_item = cur_item->next;
d4b76579b3d0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   283
			}
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   284
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   285
			while (cur_item != NULL) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   286
				// show highlighted item with a different colour
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   287
				if (cur_item == sel) GfxFillRect(w->widget[6].left + 1, y - 2, w->widget[8].right - 1, y + 9, 10);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   288
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   289
				SetDParamStr(0, cur_item->info.server_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   290
				DrawStringTruncated(w->widget[6].left + 5, y, STR_02BD, 16, max_name_width);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   291
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   292
				SetDParam(0, cur_item->info.clients_on);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   293
				SetDParam(1, cur_item->info.clients_max);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   294
				SetDParam(2, cur_item->info.companies_on);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   295
				SetDParam(3, cur_item->info.companies_max);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   296
				DrawStringCentered(210, y, STR_NETWORK_GENERAL_ONLINE, 2);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   297
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   298
				// only draw icons if the server is online
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   299
				if (cur_item->online) {
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   300
					// draw a lock if the server is password protected.
5920
16287dbdc64e (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5909
diff changeset
   301
					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[8].left + 5, y - 1);
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   302
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   303
					// draw red or green icon, depending on compatibility with server.
5920
16287dbdc64e (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5909
diff changeset
   304
					DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), w->widget[8].left + 15, y);
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   305
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   306
					// draw flag according to server language
5920
16287dbdc64e (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5909
diff changeset
   307
					DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, PAL_NONE, w->widget[8].left + 25, y);
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   308
				}
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   309
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   310
				cur_item = cur_item->next;
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   311
				y += NET_PRC__SIZE_OF_ROW;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   312
				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
   313
			}
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   314
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   315
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   316
		/* Draw the right menu */
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   317
		GfxFillRect(311, 43, 539, 92, 157);
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   318
		if (sel == NULL) {
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   319
			DrawStringCentered(425, 58, STR_NETWORK_GAME_INFO, 0);
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   320
		} else if (!sel->online) {
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   321
			SetDParamStr(0, sel->info.server_name);
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   322
			DrawStringCentered(425, 68, STR_ORANGE, 0); // game name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   323
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   324
			DrawStringCentered(425, 132, STR_NETWORK_SERVER_OFFLINE, 0); // server offline
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   325
		} else { // show game info
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   326
			uint16 y = 100;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   327
			const uint16 x = w->widget[15].left + 5;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   328
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   329
			DrawStringCentered(425, 48, STR_NETWORK_GAME_INFO, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   330
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   331
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   332
			SetDParamStr(0, sel->info.server_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   333
			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   334
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   335
			SetDParamStr(0, sel->info.map_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   336
			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 74, STR_02BD, 16); // map name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   337
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   338
			SetDParam(0, sel->info.clients_on);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   339
			SetDParam(1, sel->info.clients_max);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   340
			SetDParam(2, sel->info.companies_on);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   341
			SetDParam(3, sel->info.companies_max);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   342
			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   343
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   344
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   345
			SetDParam(0, _language_dropdown[sel->info.server_lang]);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   346
			DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   347
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   348
2775
d3ed38a97250 (svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents: 2753
diff changeset
   349
			SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   350
			DrawString(x, y, STR_NETWORK_TILESET, 2); // tileset
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   351
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   352
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   353
			SetDParam(0, sel->info.map_width);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   354
			SetDParam(1, sel->info.map_height);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   355
			DrawString(x, y, STR_NETWORK_MAP_SIZE, 2); // map size
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   356
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   357
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   358
			SetDParamStr(0, sel->info.server_revision);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   359
			DrawString(x, y, STR_NETWORK_SERVER_VERSION, 2); // server version
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   360
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   361
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   362
			SetDParamStr(0, sel->info.hostname);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   363
			SetDParam(1, sel->port);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   364
			DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   365
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   366
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   367
			SetDParam(0, sel->info.start_date);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   368
			DrawString(x, y, STR_NETWORK_START_DATE, 2); // start date
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   369
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   370
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   371
			SetDParam(0, sel->info.game_date);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   372
			DrawString(x, y, STR_NETWORK_CURRENT_DATE, 2); // current date
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   373
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   374
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   375
			y += 2;
622
3da5b736ca84 (svn r1052) -Fix: [Network] You can't join a server when revision mismatches.
truelight
parents: 621
diff changeset
   376
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   377
			if (!sel->info.compatible) {
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   378
				DrawStringCentered(425, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, 0); // server mismatch
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   379
			} else if (sel->info.clients_on == sel->info.clients_max) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   380
				// Show: server full, when clients_on == clients_max
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   381
				DrawStringCentered(425, y, STR_NETWORK_SERVER_FULL, 0); // server full
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   382
			} else if (sel->info.use_password) {
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   383
				DrawStringCentered(425, y, STR_NETWORK_PASSWORD, 0); // password warning
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   384
			}
659
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   385
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   386
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   387
		}
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   388
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   391
		nd->field = e->we.click.widget;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   392
		switch (e->we.click.widget) {
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   393
		case 0: case 14: /* Close 'X' | Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
			break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   396
		case 4: case 5:
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   397
			w->ShowDropDownMenu(_lan_internet_types_dropdown, _network_lan_internet, 5, 0, 0); // do it for widget 5
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   398
			break;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   399
		case 6: /* Sort by name */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   400
		case 7: /* Sort by connected clients */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   401
		case 8: /* Connectivity (green dot) */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   402
			if (ld->sort_type == e->we.click.widget - 6) ld->flags ^= VL_DESC;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   403
			ld->flags |= VL_RESORT;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   404
			ld->sort_type = e->we.click.widget - 6;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   405
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   406
			_ng_sorting.order = !!(ld->flags & VL_DESC);
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   407
			_ng_sorting.criteria = ld->sort_type;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   408
			w->SetDirty();
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   409
			break;
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 970
diff changeset
   410
		case 9: { /* Matrix to show networkgames */
2887
d5967e472eee (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
   411
			NetworkGameList *cur_item;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   412
			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
   413
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   414
			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
   415
			id_v += w->vscroll.pos;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   416
2887
d5967e472eee (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
   417
			cur_item = _network_game_list;
d5967e472eee (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
   418
			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
   419
2887
d5967e472eee (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
   420
			nd->server = cur_item;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   421
			w->SetDirty();
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   422
		} break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   423
		case 11: /* Find server automatically */
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   424
			switch (_network_lan_internet) {
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   425
				case 0: NetworkUDPSearchGame(); break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   426
				case 1: NetworkUDPQueryMasterServer(); break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   427
			}
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   428
			break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   429
		case 12: { // Add a server
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   430
				ShowQueryString(
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   431
				BindCString(_network_default_ip),
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   432
				STR_NETWORK_ENTER_IP,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   433
				31 | 0x1000,  // maximum number of characters OR
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   434
				250, // characters up to this width pixels, whichever is satisfied first
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
   435
				w, CS_ALPHANUMERAL);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   436
		} break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   437
		case 13: /* Start server */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   438
			ShowNetworkStartServerWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   439
			break;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   440
		case 16: /* Join Game */
2887
d5967e472eee (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
   441
			if (nd->server != NULL) {
d5967e472eee (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
   442
				snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&nd->server->ip));
d5967e472eee (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
   443
				_network_last_port = nd->server->port;
d5967e472eee (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
   444
				ShowNetworkLobbyWindow(nd->server);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   445
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   446
			break;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   447
		case 17: // Refresh
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   448
			if (nd->server != NULL)
6167
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6144
diff changeset
   449
				NetworkUDPQueryServer(nd->server->info.hostname, nd->server->port);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   450
			break;
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   451
		case 18: // NewGRF Settings
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5343
diff changeset
   452
			if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   453
			break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   454
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   455
	} 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
   456
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   457
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   458
		switch (e->we.dropdown.button) {
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   459
			case 5:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   460
				_network_lan_internet = e->we.dropdown.index;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   461
				break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   462
		}
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   463
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   464
		w->SetDirty();
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   465
		break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   466
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	case WE_MOUSELOOP:
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   468
		if (nd->field == 3) HandleEditBox(w, &WP(w, network_ql_d).q, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   471
	case WE_MESSAGE:
5035
e5680cce4e67 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   472
		if (e->we.message.msg != 0) nd->server = NULL;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   473
		ld->flags |= VL_REBUILD;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   474
		w->SetDirty();
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   475
		break;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   476
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	case WE_KEYPRESS:
2887
d5967e472eee (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
		if (nd->field != 3) {
d5967e472eee (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
   479
			if (nd->server != NULL) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   480
				if (e->we.keypress.keycode == WKC_DELETE) { /* Press 'delete' to remove servers */
2887
d5967e472eee (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
   481
					NetworkGameListRemoveItem(nd->server);
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   482
					NetworkRebuildHostList();
2887
d5967e472eee (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
   483
					nd->server = NULL;
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   484
				}
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   485
			}
741
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   486
			break;
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   487
		}
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   488
4909
ef77bf81545c (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   489
		if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   490
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   491
		// The name is only allowed when it starts with a letter!
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   492
		if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   493
			ttd_strlcpy(_network_player_name, _edit_str_buf, lengthof(_network_player_name));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   494
		} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   495
			ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   496
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   497
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   500
	case WE_ON_EDIT_TEXT:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   501
		NetworkAddServer(e->we.edittext.str);
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   502
		NetworkRebuildHostList();
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   503
		break;
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   504
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   505
	case WE_DESTROY: /* Nicely clean up the sort-list */
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   506
		free(WP(w, network_ql_d).sort_list);
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   507
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   511
static const OldWidget _network_game_window_widgets[] = {
4344
5d0e40cd67b9 (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
   512
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (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
   513
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   549,     0,    13, STR_NETWORK_MULTIPLAYER,     STR_NULL},
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   514
{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   549,    14,   263, 0x0,                         STR_NULL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   516
/* LEFT SIDE */
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   517
{      WWT_PANEL,   RESIZE_NONE,   BGC,   310,   461,    22,    33, 0x0,                         STR_NETWORK_ENTER_NAME_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   518
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   519
{      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_COMBO1,          STR_NETWORK_CONNECTION_TIP},
4344
5d0e40cd67b9 (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
   520
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                    STR_NETWORK_CONNECTION_TIP},
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   521
4344
5d0e40cd67b9 (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
   522
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   170,    42,    53, STR_NETWORK_GAME_NAME,       STR_NETWORK_GAME_NAME_TIP},
5d0e40cd67b9 (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
   523
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   171,   250,    42,    53, STR_NETWORK_CLIENTS_CAPTION, STR_NETWORK_CLIENTS_CAPTION_TIP},
5d0e40cd67b9 (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
   524
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   251,   290,    42,    53, STR_EMPTY,                   STR_NETWORK_INFO_ICONS_TIP},
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   525
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   526
{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   290,    54,   236, (13 << 8) + 1,               STR_NETWORK_CLICK_GAME_TO_SELECT},
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   527
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   291,   302,    42,   236, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
4344
5d0e40cd67b9 (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
   528
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   529
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    30,   130,   246,   257, STR_NETWORK_FIND_SERVER,     STR_NETWORK_FIND_SERVER_TIP},
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   530
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   180,   280,   246,   257, STR_NETWORK_ADD_SERVER,      STR_NETWORK_ADD_SERVER_TIP},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   531
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   532
/* RIGHT SIDE */
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   533
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   246,   257, STR_NETWORK_START_SERVER,    STR_NETWORK_START_SERVER_TIP},
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   534
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   246,   257, STR_012E_CANCEL,             STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   535
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   536
{      WWT_PANEL,   RESIZE_NONE,   BGC,   310,   540,    42,   236, 0x0,                         STR_NULL},
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   537
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   538
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   215,   226, STR_NETWORK_JOIN_GAME,       STR_NULL},
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   539
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   540
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   541
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,  STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   542
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   543
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
static const WindowDesc _network_game_window_desc = {
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   547
	WDP_CENTER, WDP_CENTER, 550, 264,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
   548
	WC_NETWORK_WINDOW, WC_NONE,
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   549
	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
   550
	_network_game_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	NetworkGameWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
   554
void ShowNetworkGameWindow()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
{
2922
61cf61d25de9 (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
   556
	static bool first = true;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   557
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 1
diff changeset
   559
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   560
	/* Only show once */
2922
61cf61d25de9 (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
   561
	if (first) {
2885
c06f2f3985a0 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2884
diff changeset
   562
		char* const *srv;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   563
2922
61cf61d25de9 (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
   564
		first = false;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   565
		// add all servers from the config file to our list
2885
c06f2f3985a0 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2884
diff changeset
   566
		for (srv = &_network_host_list[0]; srv != endof(_network_host_list) && *srv != NULL; srv++) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   567
			NetworkAddServer(*srv);
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   568
		}
2922
61cf61d25de9 (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
   569
61cf61d25de9 (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
   570
		_ng_sorting.criteria = 2; // sort default by collectivity (green-dots on top)
61cf61d25de9 (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
   571
		_ng_sorting.order = 0;    // sort ascending by default
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   572
	}
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   573
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   574
	w = BaseWindow::Allocate(&_network_game_window_desc);
2887
d5967e472eee (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
   575
	if (w != NULL) {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   576
		querystr_d *querystr = &WP(w, network_ql_d).q;
3470
9dc3e8d2fde1 (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   577
9dc3e8d2fde1 (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   578
		ttd_strlcpy(_edit_str_buf, _network_player_name, lengthof(_edit_str_buf));
5343
afb3b840ac5a (svn r7511) -Fix(r7505): Fix network game list selection by enlarging by two pixel and adding a new row to it
glx
parents: 5339
diff changeset
   579
		w->vscroll.cap = 13;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   580
4909
ef77bf81545c (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   581
		querystr->afilter = CS_ALPHANUMERAL;
4948
91dae24f3690 (svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents: 4945
diff changeset
   582
		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
   583
2887
d5967e472eee (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
   584
		UpdateNetworkGameWindow(true);
d5967e472eee (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
   585
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   586
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   587
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   588
enum {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   589
	NSSWND_START = 64,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   590
	NSSWND_ROWSIZE = 12
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   591
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   592
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   593
/* Uses network_ql_d (network_d, querystr_d and list_d) WP macro */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   594
static void NetworkStartServerWindowWndProc(BaseWindow *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
{
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   596
	network_d *nd = &WP(w, network_ql_d).n;
2887
d5967e472eee (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
   597
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   598
	switch (e->event) {
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   599
	case WE_CREATE: /* focus input box */
2887
d5967e472eee (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
   600
		nd->field = 3;
1899
98317b840d7b (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1891
diff changeset
   601
		_network_game_info.use_password = (_network_server_password[0] != '\0');
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   602
		break;
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   603
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	case WE_PAINT: {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   605
		int y = NSSWND_START, pos;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   606
		const FiosItem *item;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   607
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   608
		SetDParam( 7, _connection_types_dropdown[_network_advertise]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   609
		SetDParam( 9, _players_dropdown[_network_game_info.clients_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   610
		SetDParam(11, _players_dropdown[_network_game_info.companies_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   611
		SetDParam(13, _players_dropdown[_network_game_info.spectators_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   612
		SetDParam(15, _language_dropdown[_network_game_info.server_lang]);
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   613
		w->DrawWidgets();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   615
		GfxFillRect(11, 63, 258, 215, 0xD7);
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   616
		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   617
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		DrawString(10, 22, STR_NETWORK_NEW_GAME_NAME, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
		DrawString(10, 43, STR_NETWORK_SELECT_MAP, 2);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   621
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   622
		DrawString(280,  63, STR_NETWORK_CONNECTION, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   623
		DrawString(280,  95, STR_NETWORK_NUMBER_OF_CLIENTS, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   624
		DrawString(280, 127, STR_NETWORK_NUMBER_OF_COMPANIES, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   625
		DrawString(280, 159, STR_NETWORK_NUMBER_OF_SPECTATORS, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   626
		DrawString(280, 191, STR_NETWORK_LANGUAGE_SPOKEN, 2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   627
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   628
		if (_network_game_info.use_password) DoDrawString("*", 408, 23, 3);
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   629
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   630
		// draw list of maps
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   631
		pos = w->vscroll.pos;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   632
		while (pos < _fios_num + 1) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   633
			item = _fios_list + pos - 1;
2887
d5967e472eee (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 (item == nd->map || (pos == 0 && nd->map == NULL))
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   635
				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   636
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   637
			if (pos == 0) {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   638
				DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   639
			} else {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   640
				DoDrawString(item->title, 14, y, _fios_colors[item->type] );
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   641
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   642
			pos++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   643
			y += NSSWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   644
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   645
			if (y >= w->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   646
		}
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   647
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   650
		nd->field = e->we.click.widget;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   651
		switch (e->we.click.widget) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   652
		case 0: /* Close 'X' */
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   653
		case 19: /* Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
			break;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   656
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   657
		case 4: /* Set password button */
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
   658
			ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w, CS_ALPHANUMERAL);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   659
			break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   660
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   661
		case 5: { /* Select map */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   662
			int y = (e->we.click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   663
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   664
			y += w->vscroll.pos;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   665
			if (y >= w->vscroll.count) return;
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   666
2887
d5967e472eee (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
   667
			nd->map = (y == 0) ? NULL : _fios_list + y - 1;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   668
			w->SetDirty();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   669
			} break;
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
   670
		case 7: case 8: /* Connection type */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   671
			w->ShowDropDownMenu(_connection_types_dropdown, _network_advertise, 8, 0, 0); // do it for widget 8
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
   672
			break;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   673
		case 9: case 10: /* Number of Players (hide 0 and 1 players) */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   674
			w->ShowDropDownMenu(_players_dropdown, _network_game_info.clients_max, 10, 0, 3);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   675
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   676
		case 11: case 12: /* Number of Companies (hide 0, 9 and 10 companies; max is 8) */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   677
			w->ShowDropDownMenu(_players_dropdown, _network_game_info.companies_max, 12, 0, 1537);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   678
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   679
		case 13: case 14: /* Number of Spectators */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   680
			w->ShowDropDownMenu(_players_dropdown, _network_game_info.spectators_max, 14, 0, 0);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   681
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   682
		case 15: case 16: /* Language */
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   683
			w->ShowDropDownMenu(_language_dropdown, _network_game_info.server_lang, 16, 0, 0);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   684
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   685
		case 17: /* Start game */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   686
			_is_network_server = true;
2887
d5967e472eee (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
   687
d5967e472eee (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
   688
			if (nd->map == NULL) { // start random new game
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
   689
				ShowGenerateLandscape();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   690
			} else { // load a scenario
2887
d5967e472eee (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
   691
				char *name = FiosBrowseTo(nd->map);
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   692
				if (name != NULL) {
2887
d5967e472eee (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
   693
					SetFiosType(nd->map->type);
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   694
					ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
2887
d5967e472eee (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
   695
					ttd_strlcpy(_file_to_saveload.title, nd->map->title, sizeof(_file_to_saveload.title));
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   696
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   697
					w->Close();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
   698
					SwitchMode(SM_START_SCENARIO);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   699
				}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   700
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
			break;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   702
		case 18: /* Load game */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   703
			_is_network_server = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   704
			/* XXX - WC_NETWORK_WINDOW should stay, but if it stays, it gets
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   705
			 * copied all the elements of 'load game' and upon closing that, it segfaults */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   706
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   707
			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
   708
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
		}
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
   710
		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
   711
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
   712
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   713
		switch (e->we.dropdown.button) {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   714
			case  8: _network_advertise                = (e->we.dropdown.index != 0); break;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   715
			case 10: _network_game_info.clients_max    = e->we.dropdown.index;        break;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   716
			case 12: _network_game_info.companies_max  = e->we.dropdown.index;        break;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   717
			case 14: _network_game_info.spectators_max = e->we.dropdown.index;        break;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   718
			case 16: _network_game_info.server_lang    = e->we.dropdown.index;        break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   719
		}
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
   720
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   721
		w->SetDirty();
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
   722
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	case WE_MOUSELOOP:
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   725
		if (nd->field == 3) HandleEditBox(w, &WP(w, network_ql_d).q, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	case WE_KEYPRESS:
2887
d5967e472eee (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
   729
		if (nd->field == 3) {
4909
ef77bf81545c (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   730
			if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed
2887
d5967e472eee (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
   731
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   732
			ttd_strlcpy(_network_server_name, WP(w, network_ql_d).q.text.buf, sizeof(_network_server_name));
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   733
			UpdateTextBufferSize(&WP(w, network_ql_d).q.text);
2887
d5967e472eee (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
   734
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   736
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   737
	case WE_ON_EDIT_TEXT: {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   738
		ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password));
1899
98317b840d7b (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1891
diff changeset
   739
		_network_game_info.use_password = (_network_server_password[0] != '\0');
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   740
		w->SetDirty();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   741
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   745
static const OldWidget _network_start_server_window_widgets[] = {
4344
5d0e40cd67b9 (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
   746
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                      STR_018B_CLOSE_WINDOW },
5d0e40cd67b9 (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
   747
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_START_GAME_WINDOW, STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   748
{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   243, 0x0,                           STR_NULL},
749
ddf820fc3c53 (svn r1205) Fix: Made the network window a bit wider, so that other languages don't have overlapping strings
dominik
parents: 741
diff changeset
   749
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   750
{      WWT_PANEL,   RESIZE_NONE,   BGC,   100,   272,    22,    33, 0x0,                           STR_NETWORK_NEW_GAME_NAME_TIP},
4344
5d0e40cd67b9 (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
   751
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   285,   405,    22,    33, STR_NETWORK_SET_PASSWORD,      STR_NETWORK_PASSWORD_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   752
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   753
{      WWT_INSET,   RESIZE_NONE,   BGC,    10,   271,    62,   216, 0x0,                           STR_NETWORK_SELECT_MAP_TIP},
4344
5d0e40cd67b9 (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
   754
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   259,   270,    63,   215, 0x0,                           STR_0190_SCROLL_BAR_SCROLLS_LIST},
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   755
/* Combo boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   756
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_COMBO1,            STR_NETWORK_CONNECTION_TIP},
4344
5d0e40cd67b9 (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
   757
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                      STR_NETWORK_CONNECTION_TIP},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   758
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   109,   120, STR_NETWORK_COMBO2,            STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
4344
5d0e40cd67b9 (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
   759
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   110,   119, STR_0225,                      STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   760
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   141,   152, STR_NETWORK_COMBO3,            STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
4344
5d0e40cd67b9 (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
   761
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   142,   151, STR_0225,                      STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   762
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   173,   184, STR_NETWORK_COMBO4,            STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
4344
5d0e40cd67b9 (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
   763
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   174,   183, STR_0225,                      STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   764
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_COMBO5,            STR_NETWORK_LANGUAGE_TIP},
4344
5d0e40cd67b9 (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
   765
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                      STR_NETWORK_LANGUAGE_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   766
4344
5d0e40cd67b9 (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
   767
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    40,   140,   224,   235, STR_NETWORK_START_GAME,        STR_NETWORK_START_GAME_TIP},
5d0e40cd67b9 (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
   768
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   150,   250,   224,   235, STR_NETWORK_LOAD_GAME,         STR_NETWORK_LOAD_GAME_TIP},
5d0e40cd67b9 (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
   769
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   260,   360,   224,   235, STR_012E_CANCEL,               STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   770
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
static const WindowDesc _network_start_server_window_desc = {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   774
	WDP_CENTER, WDP_CENTER, 420, 244,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
   775
	WC_NETWORK_WINDOW, WC_NONE,
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   776
	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
   777
	_network_start_server_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	NetworkStartServerWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
   781
static void ShowNetworkStartServerWindow()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   783
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   785
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   786
	w = BaseWindow::Allocate(&_network_start_server_window_desc);
3470
9dc3e8d2fde1 (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   787
	ttd_strlcpy(_edit_str_buf, _network_server_name, lengthof(_edit_str_buf));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   788
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   789
	_saveload_mode = SLD_NEW_GAME;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   790
	BuildFileList();
2943
384c32d588e3 (svn r3499) - Fix: a few gui glitches in the network window:
Darkvater
parents: 2938
diff changeset
   791
	w->vscroll.cap = 12;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   792
	w->vscroll.count = _fios_num + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   793
4909
ef77bf81545c (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   794
	WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL;
4948
91dae24f3690 (svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents: 4945
diff changeset
   795
	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
   796
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   798
static PlayerID NetworkLobbyFindCompanyIndex(byte pos)
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   799
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   800
	PlayerID i;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   801
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   802
	/* Scroll through all _network_player_info and get the 'pos' item
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   803
	    that is not empty */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   804
	for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   805
		if (_network_player_info[i].company_name[0] != '\0') {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   806
			if (pos-- == 0) return i;
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   807
		}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   808
	}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   809
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   810
	return PLAYER_FIRST;
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   811
}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   812
2887
d5967e472eee (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
/* uses network_d WP macro */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   814
static void NetworkLobbyWindowWndProc(BaseWindow *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
{
2887
d5967e472eee (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
   816
	network_d *nd = &WP(w, network_d);
d5967e472eee (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
   817
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   818
	switch (e->event) {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   819
	case WE_CREATE:
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   820
		nd->company = INVALID_PLAYER;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   821
		break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   822
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	case WE_PAINT: {
2887
d5967e472eee (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
   824
		const NetworkGameInfo *gi = &nd->server->info;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   825
		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
   826
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6242
diff changeset
   827
		w->SetWidgetDisabledState(7, nd->company == (byte)-1);
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6242
diff changeset
   828
		w->SetWidgetDisabledState(8, gi->companies_on >= gi->companies_max);
735
5c8bacd9fa7e (svn r1187) -Fix: [Network] You can no longer join as spectator a game with no
truelight
parents: 734
diff changeset
   829
		/* You can not join a server as spectator when it has no companies active..
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   830
		 * it causes some nasty crashes */
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6242
diff changeset
   831
		w->SetWidgetDisabledState(9, gi->spectators_on >= gi->spectators_max ||
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   832
				gi->companies_on == 0);
621
334872f978c3 (svn r1051) -Fix: [Network] New Company button is disabled when there is no more
truelight
parents: 618
diff changeset
   833
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
   834
		w->DrawWidgets();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
2884
c100870ea536 (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
   836
		SetDParamStr(0, gi->server_name);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   837
		DrawString(10, 22, STR_NETWORK_PREPARE_TO_JOIN, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
2887
d5967e472eee (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
   839
		/* Draw company list */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   840
		pos = w->vscroll.pos;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   841
		while (pos < gi->companies_on) {
2887
d5967e472eee (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
   842
			byte company = NetworkLobbyFindCompanyIndex(pos);
1011
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   843
			bool income = false;
2887
d5967e472eee (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
   844
			if (nd->company == company)
d5967e472eee (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
   845
				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
   846
2887
d5967e472eee (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
   847
			DoDrawStringTruncated(_network_player_info[company].company_name, 13, y, 16, 135 - 13);
5920
16287dbdc64e (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5909
diff changeset
   848
			if (_network_player_info[company].use_password != 0) DrawSprite(SPR_LOCK, PAL_NONE, 135, y);
1011
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   849
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   850
			/* If the company's income was positive puts a green dot else a red dot */
2887
d5967e472eee (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
   851
			if (_network_player_info[company].income >= 0) income = true;
5920
16287dbdc64e (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5909
diff changeset
   852
			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
   853
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   854
			pos++;
2887
d5967e472eee (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
   855
			y += NET_PRC__SIZE_OF_ROW;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   856
			if (pos >= w->vscroll.cap) break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   857
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   858
2887
d5967e472eee (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
   859
		/* Draw info about selected company when it is selected in the left window */
d5967e472eee (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
   860
		GfxFillRect(174, 39, 403, 75, 157);
4895
4041e6fc4bc5 (svn r6854) -Codechange: Use DrawSringCentered instead of DrawStringMultiCenter for simple
Darkvater
parents: 4888
diff changeset
   861
		DrawStringCentered(290, 50, STR_NETWORK_COMPANY_INFO, 0);
2887
d5967e472eee (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
   862
		if (nd->company != (byte)-1) {
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   863
			const uint x = 183;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   864
			const uint trunc_width = w->widget[6].right - x;
2887
d5967e472eee (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
   865
			y = 80;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   866
2887
d5967e472eee (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
   867
			SetDParam(0, nd->server->info.clients_on);
d5967e472eee (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
   868
			SetDParam(1, nd->server->info.clients_max);
d5967e472eee (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
   869
			SetDParam(2, nd->server->info.companies_on);
d5967e472eee (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
   870
			SetDParam(3, nd->server->info.companies_max);
d5967e472eee (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
   871
			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
d5967e472eee (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
   872
			y += 10;
d5967e472eee (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
   873
d5967e472eee (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
   874
			SetDParamStr(0, _network_player_info[nd->company].company_name);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   875
			DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   876
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   877
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4319
diff changeset
   878
			SetDParam(0, _network_player_info[nd->company].inaugurated_year);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   879
			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   880
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   881
2887
d5967e472eee (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
   882
			SetDParam64(0, _network_player_info[nd->company].company_value);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   883
			DrawString(x, y, STR_NETWORK_VALUE, 2); // company value
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   884
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   885
2887
d5967e472eee (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
   886
			SetDParam64(0, _network_player_info[nd->company].money);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   887
			DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, 2); // current balance
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   888
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   889
2887
d5967e472eee (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
   890
			SetDParam64(0, _network_player_info[nd->company].income);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   891
			DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, 2); // last year's income
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   892
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   893
2887
d5967e472eee (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
   894
			SetDParam(0, _network_player_info[nd->company].performance);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   895
			DrawString(x, y, STR_NETWORK_PERFORMANCE, 2); // performance
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   896
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   897
2887
d5967e472eee (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
   898
			SetDParam(0, _network_player_info[nd->company].num_vehicle[0]);
d5967e472eee (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
   899
			SetDParam(1, _network_player_info[nd->company].num_vehicle[1]);
d5967e472eee (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
   900
			SetDParam(2, _network_player_info[nd->company].num_vehicle[2]);
d5967e472eee (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
   901
			SetDParam(3, _network_player_info[nd->company].num_vehicle[3]);
d5967e472eee (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
   902
			SetDParam(4, _network_player_info[nd->company].num_vehicle[4]);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   903
			DrawString(x, y, STR_NETWORK_VEHICLES, 2); // vehicles
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   904
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   905
2887
d5967e472eee (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
   906
			SetDParam(0, _network_player_info[nd->company].num_station[0]);
d5967e472eee (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
   907
			SetDParam(1, _network_player_info[nd->company].num_station[1]);
d5967e472eee (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
   908
			SetDParam(2, _network_player_info[nd->company].num_station[2]);
d5967e472eee (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
   909
			SetDParam(3, _network_player_info[nd->company].num_station[3]);
d5967e472eee (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
   910
			SetDParam(4, _network_player_info[nd->company].num_station[4]);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   911
			DrawString(x, y, STR_NETWORK_STATIONS, 2); // stations
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   912
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   913
2887
d5967e472eee (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
   914
			SetDParamStr(0, _network_player_info[nd->company].players);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   915
			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, 2, trunc_width); // players
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   916
		}
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   917
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   920
		switch (e->we.click.widget) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   921
		case 0: case 11: /* Close 'X' | Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
			break;
2887
d5967e472eee (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
   924
		case 4: { /* Company list */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   925
			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
   926
2887
d5967e472eee (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
   927
			if (id_v >= w->vscroll.cap) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   928
2887
d5967e472eee (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
   929
			id_v += w->vscroll.pos;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   930
			nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   931
			w->SetDirty();
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   932
		} break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   933
		case 7: /* Join company */
2887
d5967e472eee (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
   934
			if (nd->company != (byte)-1) {
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   935
				_network_playas = nd->company;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   936
				NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   937
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   938
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   939
		case 8: /* New company */
4861
f28bfa84f9ad (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4848
diff changeset
   940
			_network_playas = PLAYER_NEW_COMPANY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   941
			NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   942
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   943
		case 9: /* Spectate game */
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4830
diff changeset
   944
			_network_playas = PLAYER_SPECTATOR;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   945
			NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   946
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   947
		case 10: /* Refresh */
6167
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6144
diff changeset
   948
			NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6144
diff changeset
   949
			NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   950
			break;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   951
		} break;
2884
c100870ea536 (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
   952
c100870ea536 (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
   953
	case WE_MESSAGE:
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
   954
		w->SetDirty();
2884
c100870ea536 (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
   955
		break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   956
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   957
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   958
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   959
static const OldWidget _network_lobby_window_widgets[] = {
4344
5d0e40cd67b9 (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
   960
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW },
5d0e40cd67b9 (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
   961
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_GAME_LOBBY,    STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   962
{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   234, 0x0,                       STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   963
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   964
// company list
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   965
{      WWT_PANEL,   RESIZE_NONE,   BTC,    10,   155,    38,    49, 0x0,                       STR_NULL},
4344
5d0e40cd67b9 (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
   966
{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   155,    50,   190, (10 << 8) + 1,             STR_NETWORK_COMPANY_LIST_TIP},
5d0e40cd67b9 (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
   967
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   156,   167,    38,   190, STR_NULL,                  STR_0190_SCROLL_BAR_SCROLLS_LIST},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   968
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   969
// company/player info
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   970
{      WWT_PANEL,   RESIZE_NONE,   BGC,   173,   404,    38,   190, 0x0,                       STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   971
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   972
// buttons
4344
5d0e40cd67b9 (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
   973
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   200,   211, STR_NETWORK_JOIN_COMPANY,  STR_NETWORK_JOIN_COMPANY_TIP},
5d0e40cd67b9 (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
   974
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   215,   226, STR_NETWORK_NEW_COMPANY,   STR_NETWORK_NEW_COMPANY_TIP},
5d0e40cd67b9 (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
   975
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   200,   211, STR_NETWORK_SPECTATE_GAME, STR_NETWORK_SPECTATE_GAME_TIP},
5d0e40cd67b9 (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
   976
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   215,   226, STR_NETWORK_REFRESH,       STR_NETWORK_REFRESH_TIP},
5d0e40cd67b9 (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
   977
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   278,   388,   200,   211, STR_012E_CANCEL,           STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   978
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   979
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   980
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   981
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   982
static const WindowDesc _network_lobby_window_desc = {
2887
d5967e472eee (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
   983
	WDP_CENTER, WDP_CENTER, 420, 235,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
   984
	WC_NETWORK_WINDOW, WC_NONE,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   985
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   986
	_network_lobby_window_widgets,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   987
	NetworkLobbyWindowWndProc,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   988
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   989
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   990
/* Show the networklobbywindow with the selected server
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   991
 * @param ngl Selected game pointer which is passed to the new window */
2887
d5967e472eee (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
static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   993
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
   994
	BaseWindow *w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   995
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   996
6167
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6144
diff changeset
   997
	NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
1475cf991e66 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 6144
diff changeset
   998
	NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   999
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1000
	w = BaseWindow::Allocate(&_network_lobby_window_desc);
2887
d5967e472eee (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
  1001
	if (w != NULL) {
2888
0972346d11a8 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
  1002
		WP(w, network_ql_d).n.server = ngl;
2887
d5967e472eee (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
  1003
		strcpy(_edit_str_buf, "");
d5967e472eee (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
  1004
		w->vscroll.cap = 10;
d5967e472eee (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
  1005
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1006
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1007
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1008
// The window below gives information about the connected clients
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1009
//  and also makes able to give money to them, kick them (if server)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1010
//  and stuff like that.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1011
3692
01468bf49e8b (svn r4623) - Codechange: s/byte/PlayerID/
Darkvater
parents: 3470
diff changeset
  1012
extern void DrawPlayerIcon(PlayerID pid, int x, int y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1013
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1014
// Every action must be of this form
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1015
typedef void ClientList_Action_Proc(byte client_no);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1016
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1017
// Max 10 actions per client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1018
#define MAX_CLIENTLIST_ACTION 10
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1019
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1020
// Some standard bullshit.. defines variables ;)
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1021
static void ClientListWndProc(BaseWindow *w, WindowEvent *e);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1022
static void ClientListPopupWndProc(BaseWindow *w, WindowEvent *e);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1023
static byte _selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1024
static byte _selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1025
static char _clientlist_action[MAX_CLIENTLIST_ACTION][50];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1026
static ClientList_Action_Proc *_clientlist_proc[MAX_CLIENTLIST_ACTION];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1027
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1028
enum {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1029
	CLNWND_OFFSET = 16,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1030
	CLNWND_ROWSIZE = 10
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1031
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1032
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1033
static const OldWidget _client_list_widgets[] = {
2725
5c632bc5be28 (svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents: 2669
diff changeset
  1034
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1035
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_NETWORK_CLIENT_LIST,  STR_018C_WINDOW_TITLE_DRAG_THIS},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1036
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1037
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,    14 + CLNWND_ROWSIZE + 1, 0x0, STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1038
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1039
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1040
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1041
static const OldWidget _client_list_popup_widgets[] = {
4344
5d0e40cd67b9 (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
  1042
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   99,     0,     0,     0, STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1043
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1044
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1045
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1046
static WindowDesc _client_list_desc = {
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 5035
diff changeset
  1047
	WDP_AUTO, WDP_AUTO, 250, 1,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
  1048
	WC_CLIENT_LIST, WC_NONE,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1049
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1050
	_client_list_widgets,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1051
	ClientListWndProc
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1052
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1053
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1054
// Finds the Xth client-info that is active
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1055
static const NetworkClientInfo *NetworkFindClientInfo(byte client_no)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1056
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1057
	const NetworkClientInfo *ci;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
  1058
4883
801b93ae218c (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1059
	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1060
		if (client_no == 0) return ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1061
		client_no--;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1062
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1063
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1064
	return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1065
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1066
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1067
// Here we start to define the options out of the menu
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1068
static void ClientList_Kick(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1069
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1070
	if (client_no < MAX_PLAYERS)
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1071
		SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1072
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1073
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1074
static void ClientList_Ban(byte client_no)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1075
{
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1076
	uint i;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1077
	uint32 ip = NetworkFindClientInfo(client_no)->client_ip;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1078
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1079
	for (i = 0; i < lengthof(_network_ban_list); i++) {
2914
04ce2485f05f (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
  1080
		if (_network_ban_list[i] == NULL) {
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1081
			_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ip));
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1082
			break;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1083
		}
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1084
	}
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1085
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1086
	if (client_no < MAX_PLAYERS)
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1087
		SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1088
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1089
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1090
static void ClientList_GiveMoney(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1091
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1092
	if (NetworkFindClientInfo(client_no) != NULL)
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1093
		ShowNetworkGiveMoneyWindow(NetworkFindClientInfo(client_no)->client_playas);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1094
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1095
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1096
static void ClientList_SpeakToClient(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1097
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1098
	if (NetworkFindClientInfo(client_no) != NULL)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1099
		ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, NetworkFindClientInfo(client_no)->client_index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1100
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1101
4906
8a10678a62a3 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1102
static void ClientList_SpeakToCompany(byte client_no)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1103
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1104
	if (NetworkFindClientInfo(client_no) != NULL)
4906
8a10678a62a3 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1105
		ShowNetworkChatQueryWindow(DESTTYPE_TEAM, NetworkFindClientInfo(client_no)->client_playas);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1106
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1107
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1108
static void ClientList_SpeakToAll(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1109
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1110
	ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1111
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1112
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1113
static void ClientList_None(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1114
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1115
	// No action ;)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1116
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1117
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1118
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1119
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1120
// Help, a action is clicked! What do we do?
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1121
static void HandleClientListPopupClick(byte index, byte clientno) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1122
	// A click on the Popup of the ClientList.. handle the command
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1123
	if (index < MAX_CLIENTLIST_ACTION && _clientlist_proc[index] != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1124
		_clientlist_proc[index](clientno);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1125
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1126
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1127
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1128
// Finds the amount of clients and set the height correct
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1129
static bool CheckClientListHeight(BaseWindow *w)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1130
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1131
	int num = 0;
4883
801b93ae218c (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1132
	const NetworkClientInfo *ci;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1133
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1134
	// Should be replaced with a loop through all clients
4883
801b93ae218c (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1135
	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1136
		num++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1137
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1138
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1139
	num *= CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1140
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1141
	// If height is changed
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1142
	if (w->Height() != CLNWND_OFFSET + num + 1) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1143
		// XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1144
		w->SetDirty();
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1145
		w->widget[2].bottom = w->widget[2].top + num + 2;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1146
		w->SetHeight(CLNWND_OFFSET + num + 1);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1147
		w->SetDirty();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1148
		return false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1149
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1150
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1151
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1152
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1153
// Finds the amount of actions in the popup and set the height correct
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
  1154
static uint ClientListPopupHeigth() {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1155
	int i, num = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1156
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1157
	// Find the amount of actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1158
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1159
		if (_clientlist_action[i][0] == '\0') continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1160
		if (_clientlist_proc[i] == NULL) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1161
		num++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1162
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1163
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1164
	num *= CLNWND_ROWSIZE;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1165
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1166
	return num + 1;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1167
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1168
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1169
// Show the popup (action list)
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1170
static BaseWindow *PopupClientList(BaseWindow *w, int client_no, int x, int y)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1171
{
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1172
	int i, h;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1173
	const NetworkClientInfo *ci;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1174
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1175
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1176
	// Clean the current actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1177
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1178
		_clientlist_action[i][0] = '\0';
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1179
		_clientlist_proc[i] = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1180
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1181
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1182
	// Fill the actions this client has
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1183
	// Watch is, max 50 chars long!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1184
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1185
	ci = NetworkFindClientInfo(client_no);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1186
	if (ci == NULL) return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1187
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1188
	i = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1189
	if (_network_own_client_index != ci->client_index) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1190
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, lastof(_clientlist_action[i]));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1191
		_clientlist_proc[i++] = &ClientList_SpeakToClient;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1192
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1193
4945
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4943
diff changeset
  1194
	if (IsValidPlayer(ci->client_playas) || ci->client_playas == PLAYER_SPECTATOR) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1195
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(_clientlist_action[i]));
4906
8a10678a62a3 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1196
		_clientlist_proc[i++] = &ClientList_SpeakToCompany;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1197
	}
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1198
	GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, lastof(_clientlist_action[i]));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1199
	_clientlist_proc[i++] = &ClientList_SpeakToAll;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1200
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1201
	if (_network_own_client_index != ci->client_index) {
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1202
		/* We are no spectator and the player we want to give money to is no spectator */
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1203
		if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas)) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1204
			GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(_clientlist_action[i]));
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1205
			_clientlist_proc[i++] = &ClientList_GiveMoney;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1207
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1208
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1209
	// A server can kick clients (but not himself)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1210
	if (_network_server && _network_own_client_index != ci->client_index) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1211
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_KICK, lastof(_clientlist_action[i]));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1212
		_clientlist_proc[i++] = &ClientList_Kick;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1213
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1214
		sprintf(_clientlist_action[i],"Ban"); // XXX GetString?
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1215
		_clientlist_proc[i++] = &ClientList_Ban;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1216
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1217
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1218
	if (i == 0) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1219
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_NONE, lastof(_clientlist_action[i]));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1220
		_clientlist_proc[i++] = &ClientList_None;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1221
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1222
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1223
	/* Calculate the height */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1224
	h = ClientListPopupHeigth();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1225
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1226
	// Allocate the popup
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1227
	w = BaseWindow::Allocate(x, y, 150, h + 1, ClientListPopupWndProc, WC_TOOLBAR_MENU, _client_list_popup_widgets);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1228
	w->widget[0].bottom = w->widget[0].top + h;
3250
bf64b3e5f8db (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1229
	w->widget[0].right = w->widget[0].left + 150;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1230
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
  1231
	w->flash_timeout = 0;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1232
	WP(w,menu_d).item_count = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1233
	// Save our client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1234
	WP(w,menu_d).main_button = client_no;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1235
	WP(w,menu_d).sel_index = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1236
	// We are a popup
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1237
	_popup_menu_active = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1238
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1239
	return w;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1240
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1241
2887
d5967e472eee (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
  1242
/** Main handle for the client popup list
d5967e472eee (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
  1243
 * uses menu_d WP macro */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1244
static void ClientListPopupWndProc(BaseWindow *w, WindowEvent *e)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1245
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1246
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1247
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1248
		int i, y, sel;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1249
		byte colour;
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
  1250
		w->DrawWidgets();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1251
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1252
		// Draw the actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1253
		sel = WP(w,menu_d).sel_index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1254
		y = 1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1255
		for (i = 0; i < MAX_CLIENTLIST_ACTION; i++, y += CLNWND_ROWSIZE) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1256
			if (_clientlist_action[i][0] == '\0') continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1257
			if (_clientlist_proc[i] == NULL) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1258
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1259
			if (sel-- == 0) { // Selected item, highlight it
3250
bf64b3e5f8db (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1260
				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1261
				colour = 0xC;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1262
			} else {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1263
				colour = 0x10;
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1264
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1265
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1266
			DoDrawString(_clientlist_action[i], 4, y, colour);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1267
		}
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
  1268
	} break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1269
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1270
	case WE_POPUPMENU_SELECT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1271
		// We selected an action
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1272
		int index = (e->we.popupmenu.pt.y - w->Top()) / CLNWND_ROWSIZE;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1273
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1274
		if (index >= 0 && e->we.popupmenu.pt.y >= w->Top())
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1275
			HandleClientListPopupClick(index, WP(w,menu_d).main_button);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1276
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1277
		DeleteWindowById(WC_TOOLBAR_MENU, 0);
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
  1278
	} break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1279
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1280
	case WE_POPUPMENU_OVER: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1281
		// Our mouse hoovers over an action? Select it!
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1282
		int index = (e->we.popupmenu.pt.y - w->Top()) / CLNWND_ROWSIZE;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1283
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1284
		if (index == -1 || index == WP(w,menu_d).sel_index) return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1285
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1286
		WP(w,menu_d).sel_index = index;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1287
		w->SetDirty();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1288
	} break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1289
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1290
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1291
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1292
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1293
// Main handle for clientlist
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1294
static void ClientListWndProc(BaseWindow *w, WindowEvent *e)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1295
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1296
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1297
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1298
		NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1299
		int y, i = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1300
		byte colour;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1301
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1302
		// Check if we need to reset the height
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1303
		if (!CheckClientListHeight(w)) break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1304
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
  1305
		w->DrawWidgets();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1306
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1307
		y = CLNWND_OFFSET;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1308
4883
801b93ae218c (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1309
		FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1310
			if (_selected_clientlist_item == i++) { // Selected item, highlight it
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1311
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1312
				colour = 0xC;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1313
			} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1314
				colour = 0x10;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1315
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1316
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1317
			if (ci->client_index == NETWORK_SERVER_INDEX) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1318
				DrawString(4, y, STR_NETWORK_SERVER, colour);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1319
			} else {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1320
				DrawString(4, y, STR_NETWORK_CLIENT, colour);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1321
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1322
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1323
			// Filter out spectators
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1324
			if (IsValidPlayer(ci->client_playas)) DrawPlayerIcon(ci->client_playas, 64, y + 1);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1325
3250
bf64b3e5f8db (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1326
			DoDrawString(ci->client_name, 81, y, colour);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1327
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1328
			y += CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1329
		}
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
  1330
	} break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1331
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1332
	case WE_CLICK:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1333
		// Show the popup with option
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1334
		if (_selected_clientlist_item != 255) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1335
			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
  1336
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1337
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1340
	case WE_MOUSEOVER:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1341
		// -1 means we left the current window
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1342
		if (e->we.mouseover.pt.y == -1) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1343
			_selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1344
			_selected_clientlist_item = 255;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1345
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
			break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1347
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1348
		// It did not change.. no update!
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1349
		if (e->we.mouseover.pt.y == _selected_clientlist_y) break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1350
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1351
		// Find the new selected item (if any)
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1352
		_selected_clientlist_y = e->we.mouseover.pt.y;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1353
		if (e->we.mouseover.pt.y > CLNWND_OFFSET) {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1354
			_selected_clientlist_item = (e->we.mouseover.pt.y - CLNWND_OFFSET) / CLNWND_ROWSIZE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1355
		} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1356
			_selected_clientlist_item = 255;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1357
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1358
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1359
		// Repaint
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1360
		w->SetDirty();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1361
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1362
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1363
	case WE_DESTROY: case WE_CREATE:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1364
		// When created or destroyed, data is reset
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1365
		_selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1366
		_selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1367
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1368
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1369
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1370
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
  1371
void ShowClientList()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1372
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1373
	BaseWindow::AllocateFront(&_client_list_desc, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1374
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1375
4512
7151d4ee3a0f (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
  1376
7151d4ee3a0f (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
  1377
static NetworkPasswordType pw_type;
7151d4ee3a0f (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
  1378
7151d4ee3a0f (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
  1379
7151d4ee3a0f (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
  1380
void ShowNetworkNeedPassword(NetworkPasswordType npt)
7151d4ee3a0f (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
  1381
{
7151d4ee3a0f (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
  1382
	StringID caption;
7151d4ee3a0f (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
  1383
7151d4ee3a0f (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
  1384
	pw_type = npt;
7151d4ee3a0f (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
  1385
	switch (npt) {
7151d4ee3a0f (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
  1386
		default: NOT_REACHED();
4774
91b96d852ba5 (svn r6688) -Fix (r6297): Wrong caption for server password query window (eg put 'break' after switch statements)
Darkvater
parents: 4719
diff changeset
  1387
		case NETWORK_GAME_PASSWORD:    caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
91b96d852ba5 (svn r6688) -Fix (r6297): Wrong caption for server password query window (eg put 'break' after switch statements)
Darkvater
parents: 4719
diff changeset
  1388
		case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
4512
7151d4ee3a0f (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
  1389
	}
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1390
	ShowQueryString(STR_EMPTY, caption, 20, 180, BaseWindow::FindById(WC_NETWORK_STATUS_WINDOW, 0), CS_ALPHANUMERAL);
4512
7151d4ee3a0f (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
  1391
}
7151d4ee3a0f (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
  1392
7151d4ee3a0f (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
  1393
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1394
static void NetworkJoinStatusWindowWndProc(BaseWindow *w, WindowEvent *e)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1395
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1396
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1397
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1398
		uint8 progress; // used for progress bar
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
  1399
		w->DrawWidgets();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1400
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1401
		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1402
		switch (_network_join_status) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1403
			case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1404
			case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1405
				progress = 10; // first two stages 10%
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1406
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1407
			case NETWORK_JOIN_STATUS_WAITING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1408
				SetDParam(0, _network_join_waiting);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1409
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1410
				progress = 15; // third stage is 15%
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1411
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1412
			case NETWORK_JOIN_STATUS_DOWNLOADING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1413
				SetDParam(0, _network_join_kbytes);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1414
				SetDParam(1, _network_join_kbytes_total);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1415
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1416
				/* Fallthrough */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1417
			default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1418
				progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1419
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1420
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1421
		/* Draw nice progress bar :) */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1422
		DrawFrameRect(20, 18, (int)((w->Width() - 20) * progress / 100), 28, 10, FR_NONE);
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
  1423
	} break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1424
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1425
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1426
		switch (e->we.click.widget) {
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5682
diff changeset
  1427
			case 2: /* Disconnect button */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1428
				NetworkDisconnect();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1429
				w->Close();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1430
				SwitchMode(SM_MENU);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1431
				ShowNetworkGameWindow();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1432
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1435
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1436
		/* If the server asks for a password, we need to fill it in */
4512
7151d4ee3a0f (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
  1437
		case WE_ON_EDIT_TEXT_CANCEL:
7151d4ee3a0f (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
  1438
			NetworkDisconnect();
7151d4ee3a0f (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
  1439
			ShowNetworkGameWindow();
7151d4ee3a0f (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
  1440
			break;
7151d4ee3a0f (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
  1441
7151d4ee3a0f (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
  1442
		case WE_ON_EDIT_TEXT:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1443
			SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str);
4512
7151d4ee3a0f (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
  1444
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1448
static const OldWidget _network_join_status_window_widget[] = {
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5682
diff changeset
  1449
{    WWT_CAPTION,   RESIZE_NONE,    14,     0,   249,     0,    13, STR_NETWORK_CONNECTING, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1450
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,    84, 0x0,                    STR_NULL},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1451
{ 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
  1452
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1455
static const WindowDesc _network_join_status_window_desc = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1456
	WDP_CENTER, WDP_CENTER, 250, 85,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
  1457
	WC_NETWORK_STATUS_WINDOW, WC_NONE,
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5682
diff changeset
  1458
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1459
	_network_join_status_window_widget,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1460
	NetworkJoinStatusWindowWndProc,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6294
diff changeset
  1463
void ShowJoinStatusWindow()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1464
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1465
	BaseWindow *w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1466
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1467
	w = BaseWindow::Allocate(&_network_join_status_window_desc);
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5682
diff changeset
  1468
	/* Parent the status window to the lobby */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1469
	if (w != NULL) w->parent = BaseWindow::FindById(WC_NETWORK_WINDOW, 0);
670
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1470
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1472
static void SendChat(const char *buf, DestType type, byte dest)
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1473
{
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1474
	if (buf[0] == '\0') return;
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1475
	if (!_network_server) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1476
		SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1477
	} else {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1478
		NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1479
	}
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1480
}
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1481
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1482
/**
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1483
 * Find the next item of the list of things that can be auto-completed.
4319
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1484
 * @param item The current indexed item to return. This function can, and most
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1485
 *     likely will, alter item, to skip empty items in the arrays.
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1486
 * @return Returns the char that matched to the index.
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1487
 */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1488
static const char *ChatTabCompletionNextItem(uint *item)
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1489
{
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1490
	static char chat_tab_temp_buffer[64];
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1491
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1492
	/* First, try clients */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1493
	if (*item < MAX_CLIENT_INFO) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1494
		/* Skip inactive clients */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1495
		while (_network_client_info[*item].client_index == NETWORK_EMPTY_INDEX && *item < MAX_CLIENT_INFO) (*item)++;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1496
		if (*item < MAX_CLIENT_INFO) return _network_client_info[*item].client_name;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1497
	}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1498
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1499
	/* Then, try townnames */
5247
c3eece01af11 (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
  1500
	/* Not that the following assumes all town indices are adjacent, ie no
c3eece01af11 (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
  1501
	 * towns have been deleted. */
c3eece01af11 (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
  1502
	if (*item <= (uint)MAX_CLIENT_INFO + GetMaxTownIndex()) {
4319
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1503
		const Town *t;
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1504
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1505
		FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_INFO) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1506
			/* Get the town-name via the string-system */
4416
e0e9a72882d0 (svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents: 4354
diff changeset
  1507
			SetDParam(0, t->townnameparts);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1508
			GetString(chat_tab_temp_buffer, t->townnametype, lastof(chat_tab_temp_buffer));
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1509
			return &chat_tab_temp_buffer[0];
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1510
		}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1511
	}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1512
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1513
	return NULL;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1514
}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1515
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1516
/**
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1517
 * Find what text to complete. It scans for a space from the left and marks
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1518
 *  the word right from that as to complete. It also writes a \0 at the
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1519
 *  position of the space (if any). If nothing found, buf is returned.
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1520
 */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1521
static char *ChatTabCompletionFindText(char *buf)
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1522
{
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1523
	char *p = strrchr(buf, ' ');
4319
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1524
	if (p == NULL) return buf;
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1525
4319
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1526
	*p = '\0';
143de57b0e73 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1527
	return p + 1;
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1528
}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1529
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1530
/**
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1531
 * See if we can auto-complete the current text of the user.
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1532
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1533
static void ChatTabCompletion(BaseWindow *w)
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1534
{
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1535
	static char _chat_tab_completion_buf[lengthof(_edit_str_buf)];
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1536
	Textbuf *tb = &WP(w, querystr_d).text;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1537
	uint len, tb_len;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1538
	uint item;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1539
	char *tb_buf, *pre_buf;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1540
	const char *cur_name;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1541
	bool second_scan = false;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1542
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1543
	item = 0;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1544
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1545
	/* Copy the buffer so we can modify it without damaging the real data */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1546
	pre_buf = (_chat_tab_completion_active) ? strdup(_chat_tab_completion_buf) : strdup(tb->buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1547
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1548
	tb_buf  = ChatTabCompletionFindText(pre_buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1549
	tb_len  = strlen(tb_buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1550
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1551
	while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1552
		item++;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1553
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1554
		if (_chat_tab_completion_active) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1555
			/* We are pressing TAB again on the same name, is there an other name
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1556
			 *  that starts with this? */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1557
			if (!second_scan) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1558
				uint offset;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1559
				uint length;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1560
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1561
				/* If we are completing at the begin of the line, skip the ': ' we added */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1562
				if (tb_buf == pre_buf) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1563
					offset = 0;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1564
					length = tb->length - 2;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1565
				} else {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1566
					/* Else, find the place we are completing at */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1567
					offset = strlen(pre_buf) + 1;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1568
					length = tb->length - offset;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1569
				}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1570
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1571
				/* Compare if we have a match */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1572
				if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1573
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1574
				continue;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1575
			}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1576
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1577
			/* Now any match we make on _chat_tab_completion_buf after this, is perfect */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1578
		}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1579
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1580
		len = strlen(cur_name);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1581
		if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1582
			/* Save the data it was before completion */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1583
			if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1584
			_chat_tab_completion_active = true;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1585
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1586
			/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1587
			if (pre_buf == tb_buf) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1588
				snprintf(tb->buf, lengthof(_edit_str_buf), "%s: ", cur_name);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1589
			} else {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1590
				snprintf(tb->buf, lengthof(_edit_str_buf), "%s %s", pre_buf, cur_name);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1591
			}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1592
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1593
			/* Update the textbuffer */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1594
			UpdateTextBufferSize(&WP(w, querystr_d).text);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1595
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1596
			w->SetDirty();
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1597
			free(pre_buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1598
			return;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1599
		}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1600
	}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1601
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1602
	if (second_scan) {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1603
		/* We walked all posibilities, and the user presses tab again.. revert to original text */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1604
		strcpy(tb->buf, _chat_tab_completion_buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1605
		_chat_tab_completion_active = false;
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1606
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1607
		/* Update the textbuffer */
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1608
		UpdateTextBufferSize(&WP(w, querystr_d).text);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1609
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1610
		w->SetDirty();
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1611
	}
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1612
	free(pre_buf);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1613
}
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1614
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1615
/* uses querystr_d WP macro
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1616
 * uses querystr_d->caption to store
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1617
 * - type of chat message (Private/Team/All) in bytes 0-7
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1618
 * - destination of chat message in the case of Team/Private in bytes 8-15 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1619
static void ChatWindowWndProc(BaseWindow *w, WindowEvent *e)
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1620
{
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1621
	switch (e->event) {
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1622
	case WE_CREATE:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
  1623
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->Height(), 0);
1843
733f83b6483a (svn r2348) - Fix: Do not scroll the game with the arrow keys when the chatbox is open
Darkvater
parents: 1796
diff changeset
  1624
		SETBIT(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1625
		break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1626
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1627
	case WE_PAINT: {
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1628
		static const StringID chat_captions[] = {
4943
c2005edc4f84 (svn r6931) -Codechange: Change textmessage format a bit. Only the sender's name and target are
Darkvater
parents: 4939
diff changeset
  1629
			STR_NETWORK_CHAT_ALL_CAPTION,
c2005edc4f84 (svn r6931) -Codechange: Change textmessage format a bit. Only the sender's name and target are
Darkvater
parents: 4939
diff changeset
  1630
			STR_NETWORK_CHAT_COMPANY_CAPTION,
c2005edc4f84 (svn r6931) -Codechange: Change textmessage format a bit. Only the sender's name and target are
Darkvater
parents: 4939
diff changeset
  1631
			STR_NETWORK_CHAT_CLIENT_CAPTION
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1632
		};
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1633
		StringID msg;
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1634
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6235
diff changeset
  1635
		w->DrawWidgets();
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1636
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1637
		assert(GB(WP(w, querystr_d).caption, 0, 8) < lengthof(chat_captions));
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1638
		msg = chat_captions[GB(WP(w, querystr_d).caption, 0, 8)];
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1639
		DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, 16);
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1640
		DrawEditBox(w, &WP(w, querystr_d), 2);
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1641
	} break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1642
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1643
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1644
		switch (e->we.click.widget) {
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1645
			case 3: { /* Send */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1646
				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1647
				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1648
				SendChat(WP(w, querystr_d).text.buf, type, dest);
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1649
			} /* FALLTHROUGH */
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1650
			case 0: /* Cancel */ w->Close(); break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1651
		}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1652
		break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1653
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1654
	case WE_MOUSELOOP:
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1655
		HandleEditBox(w, &WP(w, querystr_d), 2);
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1656
		break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1657
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1658
	case WE_KEYPRESS:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1659
		if (e->we.keypress.keycode == WKC_TAB) {
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1660
			ChatTabCompletion(w);
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1661
		} else {
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1662
			_chat_tab_completion_active = false;
4909
ef77bf81545c (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
  1663
			switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) {
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1664
				case 1: { /* Return */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1665
				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1666
				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1667
				SendChat(WP(w, querystr_d).text.buf, type, dest);
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1668
			} /* FALLTHROUGH */
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6167
diff changeset
  1669
				case 2: /* Escape */ w->Close(); break;
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1670
			}
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1671
		}
4013
a11adcc2a852 (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1672
		break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1673
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1674
	case WE_DESTROY:
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1675
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
1843
733f83b6483a (svn r2348) - Fix: Do not scroll the game with the arrow keys when the chatbox is open
Darkvater
parents: 1796
diff changeset
  1676
		CLRBIT(_no_scroll, SCROLL_CHAT);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1677
		break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1678
	}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1679
}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1680
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1681
static const OldWidget _chat_window_widgets[] = {
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1682
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,         STR_018B_CLOSE_WINDOW},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1683
{      WWT_PANEL, RESIZE_NONE, 14,  11, 639,  0, 13, 0x0,              STR_NULL}, // background
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1684
{      WWT_PANEL, RESIZE_NONE, 14,  75, 577,  1, 12, 0x0,              STR_NULL}, // text box
4887
3fa54b371032 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1685
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 578, 639,  1, 12, STR_NETWORK_SEND, STR_NULL}, // send button
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1686
{   WIDGETS_END},
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1687
};
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1688
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1689
static const WindowDesc _chat_window_desc = {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1690
	WDP_CENTER, -26, 640, 14, // x, y, width, height
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5920
diff changeset
  1691
	WC_SEND_NETWORK_MSG, WC_NONE,
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1692
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1693
	_chat_window_widgets,
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1694
	ChatWindowWndProc
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1695
};
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1696
4888
a35f445f2722 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1697
void ShowNetworkChatQueryWindow(DestType type, byte dest)
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1698
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1699
	BaseWindow *w;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1700
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1701
	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1702
3464
72005014d00e (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
  1703
	_edit_str_buf[0] = '\0';
4315
a0fc451fad6b (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1704
	_chat_tab_completion_active = false;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1705
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6251
diff changeset
  1706
	w = BaseWindow::Allocate(&_chat_window_desc);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1707
6251
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
  1708
	w->LowerWidget(2);
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1709
	WP(w, querystr_d).caption = GB(type, 0, 8) | (dest << 8); // Misuse of caption
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1710
	WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
4957
8588d2e7f409 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4948
diff changeset
  1711
	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1712
}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1713
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1714
#endif /* ENABLE_NETWORK */