2005-07-24 14:12:37 +00:00
/* $Id$ */
2008-05-06 15:11:33 +00:00
/** @file network_gui.cpp Implementation of the Network related GUIs. */
2006-10-12 14:13:39 +00:00
# ifdef ENABLE_NETWORK
2007-01-02 17:34:03 +00:00
# include "../stdafx.h"
# include "../openttd.h"
2007-12-21 19:49:27 +00:00
# include "../strings_func.h"
2007-12-26 13:50:40 +00:00
# include "../date_func.h"
2007-01-02 17:34:03 +00:00
# include "../fios.h"
2008-05-30 18:20:26 +00:00
# include "network_internal.h"
2006-06-11 16:00:56 +00:00
# include "network_client.h"
2006-10-12 14:13:39 +00:00
# include "network_gui.h"
2004-12-20 22:14:39 +00:00
# include "network_gamelist.h"
2007-01-02 17:34:03 +00:00
# include "../gui.h"
2004-12-04 17:54:56 +00:00
# include "network_server.h"
# include "network_udp.h"
2007-12-25 11:26:07 +00:00
# include "../window_func.h"
2008-01-07 14:23:25 +00:00
# include "../string_func.h"
2008-01-09 09:45:45 +00:00
# include "../gfx_func.h"
2008-01-13 14:37:30 +00:00
# include "../settings_type.h"
2008-01-14 16:10:58 +00:00
# include "../widgets/dropdown_func.h"
2008-05-11 12:26:20 +00:00
# include "../querystring_gui.h"
2008-05-17 13:01:30 +00:00
# include "../sortlist_type.h"
2008-09-30 20:51:04 +00:00
# include "../company_base.h"
2004-08-09 17:04:08 +00:00
2008-01-13 01:21:35 +00:00
# include "table/strings.h"
# include "../table/sprites.h"
2006-01-26 16:19:24 +00:00
2007-03-07 11:47:46 +00:00
static void ShowNetworkStartServerWindow ( ) ;
2006-01-26 16:19:24 +00:00
static void ShowNetworkLobbyWindow ( NetworkGameList * ngl ) ;
2009-02-25 00:45:52 +00:00
extern void SwitchToMode ( SwitchMode new_mode ) ;
2004-08-09 17:04:08 +00:00
static const StringID _connection_types_dropdown [ ] = {
2004-12-15 21:54:07 +00:00
STR_NETWORK_LAN_INTERNET ,
STR_NETWORK_INTERNET_ADVERTISE ,
2004-08-09 17:04:08 +00:00
INVALID_STRING_ID
} ;
2004-12-22 18:42:56 +00:00
static const StringID _lan_internet_types_dropdown [ ] = {
STR_NETWORK_LAN ,
STR_NETWORK_INTERNET ,
INVALID_STRING_ID
} ;
2007-06-04 19:49:00 +00:00
static StringID _language_dropdown [ NETLANG_COUNT + 1 ] = { STR_NULL } ;
2007-06-04 16:07:22 +00:00
2007-07-25 00:16:30 +00:00
void SortNetworkLanguages ( )
{
2007-06-04 19:49:00 +00:00
/* Init the strings */
if ( _language_dropdown [ 0 ] = = STR_NULL ) {
for ( int i = 0 ; i < NETLANG_COUNT ; i + + ) _language_dropdown [ i ] = STR_NETWORK_LANG_ANY + i ;
_language_dropdown [ NETLANG_COUNT ] = INVALID_STRING_ID ;
2007-06-04 16:07:22 +00:00
}
2007-06-04 19:49:00 +00:00
/* Sort the strings (we don't move 'any' and the 'invalid' one) */
qsort ( & _language_dropdown [ 1 ] , NETLANG_COUNT - 1 , sizeof ( StringID ) , & StringIDSorter ) ;
2007-06-04 16:07:22 +00:00
}
2007-06-01 23:06:01 +00:00
2004-09-12 14:12:33 +00:00
enum {
2006-01-25 19:03:50 +00:00
NET_PRC__OFFSET_TOP_WIDGET = 54 ,
2006-01-26 16:19:24 +00:00
NET_PRC__OFFSET_TOP_WIDGET_COMPANY = 52 ,
2006-01-25 19:03:50 +00:00
NET_PRC__SIZE_OF_ROW = 14 ,
2004-09-12 14:12:33 +00:00
} ;
2006-11-06 00:14:36 +00:00
/** Update the network new window because a new server is
* found on the network .
* @ param unselect unselect the currently selected item */
2005-01-05 10:47:59 +00:00
void UpdateNetworkGameWindow ( bool unselect )
{
2009-01-17 16:53:32 +00:00
InvalidateWindowData ( WC_NETWORK_WINDOW , 0 , unselect ? 1 : 0 ) ;
2005-01-05 10:47:59 +00:00
}
2007-11-24 21:41:59 +00:00
/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
enum NetworkGameWindowWidgets {
2008-04-14 13:23:16 +00:00
NGWW_CLOSE , ///< Close 'X' button
NGWW_CAPTION , ///< Caption of the window
2009-03-15 15:22:09 +00:00
NGWW_MAIN , ///< Main panel
2007-11-24 21:41:59 +00:00
2008-04-14 13:23:16 +00:00
NGWW_CONNECTION , ///< Label in from of connection droplist
NGWW_CONN_BTN , ///< 'Connection' droplist button
2008-09-30 20:39:50 +00:00
NGWW_CLIENT , ///< Panel with editbox to set client name
2008-04-14 13:23:16 +00:00
NGWW_NAME , ///< 'Name' button
2007-11-24 21:41:59 +00:00
NGWW_CLIENTS , ///< 'Clients' button
2008-07-18 20:44:35 +00:00
NGWW_MAPSIZE , ///< 'Map size' button
NGWW_DATE , ///< 'Date' button
NGWW_YEARS , ///< 'Years' button
2007-11-24 21:41:59 +00:00
NGWW_INFO , ///< Third button in the game list panel
2008-04-14 13:23:16 +00:00
NGWW_MATRIX , ///< Panel with list of games
NGWW_SCROLLBAR , ///< Scrollbar of matrix
2007-11-24 21:41:59 +00:00
2008-04-14 20:31:21 +00:00
NGWW_LASTJOINED_LABEL , ///< Label "Last joined server:"
NGWW_LASTJOINED , ///< Info about the last joined server
2008-04-14 13:23:16 +00:00
NGWW_DETAILS , ///< Panel with game details
NGWW_JOIN , ///< 'Join game' button
NGWW_REFRESH , ///< 'Refresh server' button
NGWW_NEWGRF , ///< 'NewGRF Settings' button
2007-11-24 21:41:59 +00:00
2008-04-14 13:23:16 +00:00
NGWW_FIND , ///< 'Find server' button
2007-11-24 21:41:59 +00:00
NGWW_ADD , ///< 'Add server' button
NGWW_START , ///< 'Start server' button
NGWW_CANCEL , ///< 'Cancel' button
2009-03-15 15:22:09 +00:00
NGWW_RESIZE , ///< Resize button
2007-11-24 21:41:59 +00:00
} ;
2008-05-11 14:23:45 +00:00
typedef GUIList < NetworkGameList * > GUIGameServerList ;
2008-10-22 20:22:18 +00:00
typedef uint16 ServerListPosition ;
static const ServerListPosition SLP_INVALID = 0xFFFF ;
2008-05-11 14:23:45 +00:00
2008-05-29 16:37:26 +00:00
class NetworkGameWindow : public QueryStringBaseWindow {
protected :
/* Runtime saved values */
static Listing last_sorting ;
/* Constants for sorting servers */
2009-03-15 16:04:39 +00:00
static GUIGameServerList : : SortFunction * const sorter_funcs [ ] ;
2008-05-29 16:37:26 +00:00
2009-04-15 20:37:00 +00:00
byte field ; ///< selected text-field
NetworkGameList * server ; ///< selected server
NetworkGameList * last_joined ; ///< the last joined server
GUIGameServerList servers ; ///< list with game servers.
ServerListPosition list_pos ; ///< position of the selected server
2008-04-14 20:31:21 +00:00
2008-05-11 12:26:20 +00:00
/**
* ( Re ) build the network game list as its amount has changed because
* an item has been added or deleted for example
*/
void BuildNetworkGameList ( )
{
2008-05-29 16:37:26 +00:00
if ( ! this - > servers . NeedRebuild ( ) ) return ;
2007-07-27 19:57:52 +00:00
2008-05-11 12:26:20 +00:00
/* Create temporary array of games to use for listing */
2008-05-26 16:23:23 +00:00
this - > servers . Clear ( ) ;
2005-11-13 13:43:55 +00:00
2008-05-26 16:23:23 +00:00
for ( NetworkGameList * ngl = _network_game_list ; ngl ! = NULL ; ngl = ngl - > next ) {
* this - > servers . Append ( ) = ngl ;
2008-05-11 12:26:20 +00:00
}
2006-01-26 17:10:11 +00:00
2008-05-26 16:23:23 +00:00
this - > servers . Compact ( ) ;
2008-05-29 16:37:26 +00:00
this - > servers . RebuildDone ( ) ;
}
2008-05-26 16:23:23 +00:00
2008-05-29 16:37:26 +00:00
/** Sort servers by name. */
2009-01-10 00:31:47 +00:00
static int CDECL NGameNameSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-05-29 16:37:26 +00:00
{
return strcasecmp ( ( * a ) - > info . server_name , ( * b ) - > info . server_name ) ;
2008-05-11 12:26:20 +00:00
}
2008-03-26 10:38:31 +00:00
2008-05-29 16:37:26 +00:00
/** Sort servers by the amount of clients online on a
* server . If the two servers have the same amount , the one with the
* higher maximum is preferred . */
2009-01-10 00:31:47 +00:00
static int CDECL NGameClientSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-05-11 12:26:20 +00:00
{
2008-05-29 16:37:26 +00:00
/* Reverse as per default we are interested in most-clients first */
int r = ( * a ) - > info . clients_on - ( * b ) - > info . clients_on ;
if ( r = = 0 ) r = ( * a ) - > info . clients_max - ( * b ) - > info . clients_max ;
if ( r = = 0 ) r = NGameNameSorter ( a , b ) ;
2008-05-11 12:26:20 +00:00
2008-05-29 16:37:26 +00:00
return r ;
}
2008-05-11 12:26:20 +00:00
2008-07-18 20:44:35 +00:00
/** Sort servers by map size */
2009-01-10 00:31:47 +00:00
static int CDECL NGameMapSizeSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-07-18 20:44:35 +00:00
{
/* Sort by the area of the map. */
int r = ( ( * a ) - > info . map_height ) * ( ( * a ) - > info . map_width ) - ( ( * b ) - > info . map_height ) * ( ( * b ) - > info . map_width ) ;
if ( r = = 0 ) r = ( * a ) - > info . map_width - ( * b ) - > info . map_width ;
return ( r ! = 0 ) ? r : NGameClientSorter ( a , b ) ;
}
/** Sort servers by current date */
2009-01-10 00:31:47 +00:00
static int CDECL NGameDateSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-07-18 20:44:35 +00:00
{
int r = ( * a ) - > info . game_date - ( * b ) - > info . game_date ;
return ( r ! = 0 ) ? r : NGameClientSorter ( a , b ) ;
}
/** Sort servers by the number of days the game is running */
2009-01-10 00:31:47 +00:00
static int CDECL NGameYearsSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-07-18 20:44:35 +00:00
{
int r = ( * a ) - > info . game_date - ( * a ) - > info . start_date - ( * b ) - > info . game_date + ( * b ) - > info . start_date ;
return ( r ! = 0 ) ? r : NGameDateSorter ( a , b ) ;
}
2008-05-29 16:37:26 +00:00
/** Sort servers by joinability. If both servers are the
* same , prefer the non - passworded server first . */
2009-01-10 00:31:47 +00:00
static int CDECL NGameAllowedSorter ( NetworkGameList * const * a , NetworkGameList * const * b )
2008-05-29 16:37:26 +00:00
{
/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
int r = StrEmpty ( ( * a ) - > info . server_revision ) - StrEmpty ( ( * b ) - > info . server_revision ) ;
/* Reverse default as we are interested in version-compatible clients first */
if ( r = = 0 ) r = ( * b ) - > info . version_compatible - ( * a ) - > info . version_compatible ;
/* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
if ( r = = 0 ) r = ( * b ) - > info . compatible - ( * a ) - > info . compatible ;
/* Passworded servers should be below unpassworded servers */
if ( r = = 0 ) r = ( * a ) - > info . use_password - ( * b ) - > info . use_password ;
/* Finally sort on the name of the server */
if ( r = = 0 ) r = NGameNameSorter ( a , b ) ;
return r ;
}
2008-05-11 12:26:20 +00:00
2008-05-29 16:37:26 +00:00
/** Sort the server list */
void SortNetworkGameList ( )
{
if ( ! this - > servers . Sort ( ) ) return ;
2008-05-11 12:26:20 +00:00
/* After sorting ngl->sort_list contains the sorted items. Put these back
* into the original list . Basically nothing has changed , we are only
2008-10-22 20:22:18 +00:00
* shuffling the - > next pointers . While iterating , look for the
* currently selected server and set list_pos to its position */
this - > list_pos = SLP_INVALID ;
2008-05-26 16:23:23 +00:00
_network_game_list = this - > servers [ 0 ] ;
2008-05-29 16:37:26 +00:00
NetworkGameList * item = _network_game_list ;
2008-10-22 20:22:18 +00:00
if ( item = = this - > server ) this - > list_pos = 0 ;
2008-05-29 16:37:26 +00:00
for ( uint i = 1 ; i ! = this - > servers . Length ( ) ; i + + ) {
2008-05-26 16:23:23 +00:00
item - > next = this - > servers [ i ] ;
2008-05-11 12:26:20 +00:00
item = item - > next ;
2008-10-22 20:22:18 +00:00
if ( item = = this - > server ) this - > list_pos = i ;
2008-05-11 12:26:20 +00:00
}
item - > next = NULL ;
}
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
/**
* Draw a single server line .
* @ param cur_item the server to draw .
* @ param y from where to draw ?
* @ param highlight does the line need to be highlighted ?
*/
void DrawServerLine ( const NetworkGameList * cur_item , uint y , bool highlight )
{
/* show highlighted item with a different colour */
if ( highlight ) GfxFillRect ( this - > widget [ NGWW_NAME ] . left + 1 , y - 2 , this - > widget [ NGWW_INFO ] . right - 1 , y + 9 , 10 ) ;
2006-01-26 17:10:11 +00:00
2009-04-26 15:42:45 +00:00
DrawString ( this - > widget [ NGWW_NAME ] . left + 5 , this - > widget [ NGWW_NAME ] . right , y , cur_item - > info . server_name , TC_BLACK ) ;
2004-12-27 10:24:38 +00:00
2008-07-18 20:44:35 +00:00
/* only draw details if the server is online */
2008-05-11 12:26:20 +00:00
if ( cur_item - > online ) {
2008-07-18 20:44:35 +00:00
SetDParam ( 0 , cur_item - > info . clients_on ) ;
SetDParam ( 1 , cur_item - > info . clients_max ) ;
SetDParam ( 2 , cur_item - > info . companies_on ) ;
SetDParam ( 3 , cur_item - > info . companies_max ) ;
2009-04-26 15:26:19 +00:00
DrawString ( this - > widget [ NGWW_CLIENTS ] . left , this - > widget [ NGWW_CLIENTS ] . right , y , STR_NETWORK_GENERAL_ONLINE , TC_FROMSTRING , SA_CENTER ) ;
2008-07-18 20:44:35 +00:00
/* map size */
if ( ! this - > IsWidgetHidden ( NGWW_MAPSIZE ) ) {
SetDParam ( 0 , cur_item - > info . map_width ) ;
SetDParam ( 1 , cur_item - > info . map_height ) ;
2009-04-26 15:26:19 +00:00
DrawString ( this - > widget [ NGWW_MAPSIZE ] . left , this - > widget [ NGWW_MAPSIZE ] . right , y , STR_NETWORK_MAP_SIZE_SHORT , TC_FROMSTRING , SA_CENTER ) ;
2008-07-18 20:44:35 +00:00
}
/* current date */
if ( ! this - > IsWidgetHidden ( NGWW_DATE ) ) {
YearMonthDay ymd ;
ConvertDateToYMD ( cur_item - > info . game_date , & ymd ) ;
SetDParam ( 0 , ymd . year ) ;
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DATE ] . left , this - > widget [ NGWW_DATE ] . right , y , STR_JUST_INT , TC_BLACK , SA_CENTER ) ;
2008-07-18 20:44:35 +00:00
}
/* number of years the game is running */
if ( ! this - > IsWidgetHidden ( NGWW_YEARS ) ) {
YearMonthDay ymd_cur , ymd_start ;
ConvertDateToYMD ( cur_item - > info . game_date , & ymd_cur ) ;
ConvertDateToYMD ( cur_item - > info . start_date , & ymd_start ) ;
SetDParam ( 0 , ymd_cur . year - ymd_start . year ) ;
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_YEARS ] . left , this - > widget [ NGWW_YEARS ] . right , y , STR_JUST_INT , TC_BLACK , SA_CENTER ) ;
2008-07-18 20:44:35 +00:00
}
2008-05-11 12:26:20 +00:00
/* draw a lock if the server is password protected */
if ( cur_item - > info . use_password ) DrawSprite ( SPR_LOCK , PAL_NONE , this - > widget [ NGWW_INFO ] . left + 5 , y - 1 ) ;
2004-12-10 22:01:17 +00:00
2008-05-11 12:26:20 +00:00
/* draw red or green icon, depending on compatibility with server */
DrawSprite ( SPR_BLOT , ( cur_item - > info . compatible ? PALETTE_TO_GREEN : ( cur_item - > info . version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED ) ) , this - > widget [ NGWW_INFO ] . left + 15 , y ) ;
2004-12-04 17:54:56 +00:00
2008-05-11 12:26:20 +00:00
/* draw flag according to server language */
DrawSprite ( SPR_FLAGS_BASE + cur_item - > info . server_lang , PAL_NONE , this - > widget [ NGWW_INFO ] . left + 25 , y ) ;
}
}
2008-03-26 10:38:31 +00:00
2008-10-22 20:22:18 +00:00
/**
* Scroll the list up or down to the currently selected server .
* If the server is below the currently displayed servers , it will
* scroll down an amount so that the server appears at the bottom .
* If the server is above the currently displayed servers , it will
* scroll up so that the server appears at the top .
*/
void ScrollToSelectedServer ( )
{
if ( this - > list_pos = = SLP_INVALID ) return ; // no server selected
if ( this - > list_pos < this - > vscroll . pos ) {
/* scroll up to the server */
this - > vscroll . pos = this - > list_pos ;
} else if ( this - > list_pos > = this - > vscroll . pos + this - > vscroll . cap ) {
/* scroll down so that the server is at the bottom */
this - > vscroll . pos = this - > list_pos - this - > vscroll . cap + 1 ;
}
}
2008-05-29 16:37:26 +00:00
public :
2009-04-08 19:39:03 +00:00
NetworkGameWindow ( const WindowDesc * desc ) : QueryStringBaseWindow ( NETWORK_CLIENT_NAME_LENGTH , desc )
2008-05-29 16:37:26 +00:00
{
2009-03-22 21:16:57 +00:00
this - > widget [ NGWW_CLIENTS ] . left = this - > widget [ NGWW_NAME ] . right + 1 ;
this - > widget [ NGWW_MAPSIZE ] . left = this - > widget [ NGWW_NAME ] . right + 1 ;
this - > widget [ NGWW_DATE ] . left = this - > widget [ NGWW_NAME ] . right + 1 ;
this - > widget [ NGWW_YEARS ] . left = this - > widget [ NGWW_NAME ] . right + 1 ;
this - > widget [ NGWW_CLIENTS ] . right = this - > widget [ NGWW_INFO ] . left - 1 ;
this - > widget [ NGWW_MAPSIZE ] . right = this - > widget [ NGWW_INFO ] . left - 1 ;
this - > widget [ NGWW_DATE ] . right = this - > widget [ NGWW_INFO ] . left - 1 - 20 ;
this - > widget [ NGWW_YEARS ] . right = this - > widget [ NGWW_INFO ] . left - 1 - 20 ;
this - > widget [ NGWW_NAME ] . display_flags & = ~ RESIZE_LRTB ;
this - > widget [ NGWW_CLIENTS ] . display_flags & = ~ RESIZE_LRTB ;
this - > widget [ NGWW_MAPSIZE ] . display_flags & = ~ RESIZE_LRTB ;
this - > widget [ NGWW_DATE ] . display_flags & = ~ RESIZE_LRTB ;
this - > widget [ NGWW_YEARS ] . display_flags & = ~ RESIZE_LRTB ;
2008-09-30 20:39:50 +00:00
ttd_strlcpy ( this - > edit_str_buf , _settings_client . network . client_name , this - > edit_str_size ) ;
2008-05-29 16:37:26 +00:00
this - > afilter = CS_ALPHANUMERAL ;
2008-08-11 22:08:56 +00:00
InitializeTextBuffer ( & this - > text , this - > edit_str_buf , this - > edit_str_size , 120 ) ;
2009-02-09 01:22:29 +00:00
this - > SetFocusedWidget ( NGWW_CLIENT ) ;
2008-05-29 16:37:26 +00:00
UpdateNetworkGameWindow ( true ) ;
this - > vscroll . cap = 11 ;
this - > resize . step_height = NET_PRC__SIZE_OF_ROW ;
2008-09-30 20:39:50 +00:00
this - > field = NGWW_CLIENT ;
2008-05-29 16:37:26 +00:00
this - > server = NULL ;
2008-10-22 20:22:18 +00:00
this - > list_pos = SLP_INVALID ;
2008-05-29 16:37:26 +00:00
2009-04-15 20:37:00 +00:00
this - > last_joined = NetworkGameListAddItem ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ;
2008-05-29 16:37:26 +00:00
this - > servers . SetListing ( this - > last_sorting ) ;
this - > servers . SetSortFuncs ( this - > sorter_funcs ) ;
this - > servers . ForceRebuild ( ) ;
this - > SortNetworkGameList ( ) ;
this - > FindWindowPlacementAndResize ( desc ) ;
}
~ NetworkGameWindow ( )
{
this - > last_sorting = this - > servers . GetListing ( ) ;
}
2008-05-11 12:26:20 +00:00
virtual void OnPaint ( )
{
2009-04-08 12:52:53 +00:00
NetworkGameList * sel = this - > server ;
2008-05-29 16:37:26 +00:00
const SortButtonState arrow = this - > servers . IsDescSortOrder ( ) ? SBS_DOWN : SBS_UP ;
2004-12-15 00:31:08 +00:00
2008-05-29 16:37:26 +00:00
if ( this - > servers . NeedRebuild ( ) ) {
2008-05-11 12:26:20 +00:00
this - > BuildNetworkGameList ( ) ;
2008-05-26 16:23:23 +00:00
SetVScrollCount ( this , this - > servers . Length ( ) ) ;
2008-05-11 12:26:20 +00:00
}
2008-05-29 16:37:26 +00:00
this - > SortNetworkGameList ( ) ;
2008-05-11 12:26:20 +00:00
/* 'Refresh' button invisible if no server selected */
this - > SetWidgetDisabledState ( NGWW_REFRESH , sel = = NULL ) ;
/* 'Join' button disabling conditions */
this - > SetWidgetDisabledState ( NGWW_JOIN , sel = = NULL | | // no Selected Server
! sel - > online | | // Server offline
sel - > info . clients_on > = sel - > info . clients_max | | // Server full
! sel - > info . compatible ) ; // Revision mismatch
/* 'NewGRF Settings' button invisible if no NewGRF is used */
this - > SetWidgetHiddenState ( NGWW_NEWGRF , sel = = NULL | |
! sel - > online | |
sel - > info . grfconfig = = NULL ) ;
SetDParam ( 0 , 0x00 ) ;
2008-05-29 20:21:28 +00:00
SetDParam ( 1 , _lan_internet_types_dropdown [ _settings_client . network . lan_internet ] ) ;
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2004-08-09 17:04:08 +00:00
2008-09-30 20:39:50 +00:00
/* Edit box to set client name */
this - > DrawEditBox ( NGWW_CLIENT ) ;
2004-09-12 14:12:33 +00:00
2009-04-26 15:26:19 +00:00
DrawString ( 0 , this - > widget [ NGWW_CLIENT ] . left - 5 , 23 , STR_NETWORK_PLAYER_NAME , TC_FROMSTRING , SA_RIGHT ) ;
2004-09-12 14:12:33 +00:00
2008-05-11 12:26:20 +00:00
/* Sort based on widgets: name, clients, compatibility */
2008-05-29 16:37:26 +00:00
switch ( this - > servers . SortType ( ) ) {
2008-05-17 12:48:06 +00:00
case NGWW_NAME - NGWW_NAME : this - > DrawSortButtonState ( NGWW_NAME , arrow ) ; break ;
case NGWW_CLIENTS - NGWW_NAME : this - > DrawSortButtonState ( NGWW_CLIENTS , arrow ) ; break ;
2008-07-18 20:44:35 +00:00
case NGWW_MAPSIZE - NGWW_NAME : if ( ! this - > IsWidgetHidden ( NGWW_MAPSIZE ) ) this - > DrawSortButtonState ( NGWW_MAPSIZE , arrow ) ; break ;
case NGWW_DATE - NGWW_NAME : if ( ! this - > IsWidgetHidden ( NGWW_DATE ) ) this - > DrawSortButtonState ( NGWW_DATE , arrow ) ; break ;
case NGWW_YEARS - NGWW_NAME : if ( ! this - > IsWidgetHidden ( NGWW_YEARS ) ) this - > DrawSortButtonState ( NGWW_YEARS , arrow ) ; break ;
2008-05-17 12:48:06 +00:00
case NGWW_INFO - NGWW_NAME : this - > DrawSortButtonState ( NGWW_INFO , arrow ) ; break ;
2008-05-11 12:26:20 +00:00
}
2004-12-04 17:54:56 +00:00
2008-05-11 12:26:20 +00:00
uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3 ;
2008-03-26 10:38:31 +00:00
2008-06-04 22:30:44 +00:00
const int max = min ( this - > vscroll . pos + this - > vscroll . cap , ( int ) this - > servers . Length ( ) ) ;
2008-03-26 10:38:31 +00:00
2008-05-29 16:37:26 +00:00
for ( int i = this - > vscroll . pos ; i < max ; + + i ) {
const NetworkGameList * ngl = this - > servers [ i ] ;
this - > DrawServerLine ( ngl , y , ngl = = sel ) ;
2008-05-11 12:26:20 +00:00
y + = NET_PRC__SIZE_OF_ROW ;
}
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
/* Draw the last joined server, if any */
2009-04-15 20:37:00 +00:00
if ( this - > last_joined ! = NULL ) this - > DrawServerLine ( this - > last_joined , y = this - > widget [ NGWW_LASTJOINED ] . top + 3 , this - > last_joined = = sel ) ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
/* Draw the right menu */
GfxFillRect ( this - > widget [ NGWW_DETAILS ] . left + 1 , 43 , this - > widget [ NGWW_DETAILS ] . right - 1 , 92 , 157 ) ;
if ( sel = = NULL ) {
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , 58 , STR_NETWORK_GAME_INFO , TC_FROMSTRING , SA_CENTER ) ;
2008-05-11 12:26:20 +00:00
} else if ( ! sel - > online ) {
2009-04-26 15:42:45 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , 68 , sel - > info . server_name , TC_ORANGE , SA_CENTER ) ; // game name
2008-04-14 20:31:21 +00:00
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , 132 , STR_NETWORK_SERVER_OFFLINE , TC_FROMSTRING , SA_CENTER ) ; // server offline
2008-05-11 12:26:20 +00:00
} else { // show game info
uint16 y = 100 ;
const uint16 x = this - > widget [ NGWW_DETAILS ] . left + 5 ;
2008-03-26 10:38:31 +00:00
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , 48 , STR_NETWORK_GAME_INFO , TC_FROMSTRING , SA_CENTER ) ;
2008-03-26 10:38:31 +00:00
2009-04-26 15:42:45 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left , this - > widget [ NGWW_DETAILS ] . right , 62 , sel - > info . server_name , TC_ORANGE , SA_CENTER ) ; // game name
DrawString ( this - > widget [ NGWW_DETAILS ] . left , this - > widget [ NGWW_DETAILS ] . right , 74 , sel - > info . map_name , TC_BLACK , SA_CENTER ) ; // map name
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
SetDParam ( 0 , sel - > info . clients_on ) ;
SetDParam ( 1 , sel - > info . clients_max ) ;
SetDParam ( 2 , sel - > info . companies_on ) ;
SetDParam ( 3 , sel - > info . companies_max ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_CLIENTS ) ;
2008-05-11 12:26:20 +00:00
y + = 10 ;
2004-12-04 17:54:56 +00:00
2008-05-11 12:26:20 +00:00
SetDParam ( 0 , STR_NETWORK_LANG_ANY + sel - > info . server_lang ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_LANGUAGE ) ; // server language
2008-05-11 12:26:20 +00:00
y + = 10 ;
SetDParam ( 0 , STR_TEMPERATE_LANDSCAPE + sel - > info . map_set ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_TILESET ) ; // tileset
2008-05-11 12:26:20 +00:00
y + = 10 ;
SetDParam ( 0 , sel - > info . map_width ) ;
SetDParam ( 1 , sel - > info . map_height ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_MAP_SIZE ) ; // map size
2008-05-11 12:26:20 +00:00
y + = 10 ;
SetDParamStr ( 0 , sel - > info . server_revision ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_SERVER_VERSION ) ; // server version
2008-05-11 12:26:20 +00:00
y + = 10 ;
2009-04-08 12:52:53 +00:00
SetDParamStr ( 0 , sel - > address . GetAddressAsString ( ) ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_SERVER_ADDRESS ) ; // server address
2008-05-11 12:26:20 +00:00
y + = 10 ;
2004-09-06 22:46:02 +00:00
2008-05-11 12:26:20 +00:00
SetDParam ( 0 , sel - > info . start_date ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_START_DATE ) ; // start date
2008-05-11 12:26:20 +00:00
y + = 10 ;
SetDParam ( 0 , sel - > info . game_date ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NGWW_DETAILS ] . right , y , STR_NETWORK_CURRENT_DATE ) ; // current date
2008-05-11 12:26:20 +00:00
y + = 10 ;
y + = 2 ;
if ( ! sel - > info . compatible ) {
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , y , sel - > info . version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH , TC_FROMSTRING , SA_CENTER ) ; // server mismatch
2008-05-11 12:26:20 +00:00
} else if ( sel - > info . clients_on = = sel - > info . clients_max ) {
2008-06-03 08:04:35 +00:00
/* Show: server full, when clients_on == max_clients */
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , y , STR_NETWORK_SERVER_FULL , TC_FROMSTRING , SA_CENTER ) ; // server full
2008-05-11 12:26:20 +00:00
} else if ( sel - > info . use_password ) {
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NGWW_DETAILS ] . left + 1 , this - > widget [ NGWW_DETAILS ] . right - 1 , y , STR_NETWORK_PASSWORD , TC_FROMSTRING , SA_CENTER ) ; // password warning
2008-03-26 10:38:31 +00:00
}
2004-12-22 18:42:56 +00:00
2008-05-11 12:26:20 +00:00
y + = 10 ;
}
}
2004-12-22 18:42:56 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnClick ( Point pt , int widget )
{
this - > field = widget ;
switch ( widget ) {
case NGWW_CANCEL : // Cancel button
DeleteWindowById ( WC_NETWORK_WINDOW , 0 ) ;
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_CONN_BTN : // 'Connection' droplist
2008-05-29 20:21:28 +00:00
ShowDropDownMenu ( this , _lan_internet_types_dropdown , _settings_client . network . lan_internet , NGWW_CONN_BTN , 0 , 0 ) ; // do it for widget NSSW_CONN_BTN
2008-05-11 12:26:20 +00:00
break ;
2008-07-18 20:44:35 +00:00
case NGWW_NAME : // Sort by name
2008-05-11 12:26:20 +00:00
case NGWW_CLIENTS : // Sort by connected clients
2008-07-18 20:44:35 +00:00
case NGWW_MAPSIZE : // Sort by map size
case NGWW_DATE : // Sort by date
case NGWW_YEARS : // Sort by years
case NGWW_INFO : // Connectivity (green dot)
2008-05-29 16:37:26 +00:00
if ( this - > servers . SortType ( ) = = widget - NGWW_NAME ) {
this - > servers . ToggleSortOrder ( ) ;
2008-10-22 20:22:18 +00:00
if ( this - > list_pos ! = SLP_INVALID ) this - > list_pos = this - > servers . Length ( ) - this - > list_pos - 1 ;
2008-05-29 16:37:26 +00:00
} else {
this - > servers . SetSortType ( widget - NGWW_NAME ) ;
this - > servers . ForceResort ( ) ;
2008-10-22 20:22:18 +00:00
this - > SortNetworkGameList ( ) ;
2008-05-29 16:37:26 +00:00
}
2008-10-22 20:22:18 +00:00
this - > ScrollToSelectedServer ( ) ;
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
break ;
case NGWW_MATRIX : { // Matrix to show networkgames
uint32 id_v = ( pt . y - NET_PRC__OFFSET_TOP_WIDGET ) / NET_PRC__SIZE_OF_ROW ;
if ( id_v > = this - > vscroll . cap ) return ; // click out of bounds
id_v + = this - > vscroll . pos ;
2008-05-29 16:47:22 +00:00
this - > server = ( id_v < this - > servers . Length ( ) ) ? this - > servers [ id_v ] : NULL ;
2008-10-22 20:22:18 +00:00
this - > list_pos = ( server = = NULL ) ? SLP_INVALID : id_v ;
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
} break ;
case NGWW_LASTJOINED : {
2009-04-02 20:17:46 +00:00
NetworkGameList * last_joined = NetworkGameListAddItem ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ;
2008-05-11 12:26:20 +00:00
if ( last_joined ! = NULL ) {
this - > server = last_joined ;
2008-10-22 20:22:18 +00:00
/* search the position of the newly selected server */
for ( uint i = 0 ; i < this - > servers . Length ( ) ; i + + ) {
if ( this - > servers [ i ] = = this - > server ) {
this - > list_pos = i ;
break ;
}
}
this - > ScrollToSelectedServer ( ) ;
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
}
} break ;
case NGWW_FIND : // Find server automatically
2008-05-29 20:21:28 +00:00
switch ( _settings_client . network . lan_internet ) {
2008-05-11 12:26:20 +00:00
case 0 : NetworkUDPSearchGame ( ) ; break ;
case 1 : NetworkUDPQueryMasterServer ( ) ; break ;
2004-12-20 22:14:39 +00:00
}
2008-03-26 10:38:31 +00:00
break ;
2004-12-21 14:54:27 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_ADD : // Add a server
2008-07-17 13:47:04 +00:00
SetDParamStr ( 0 , _settings_client . network . connect_to_ip ) ;
2008-05-11 12:26:20 +00:00
ShowQueryString (
2008-07-17 13:47:04 +00:00
STR_JUST_RAW_STRING ,
2008-05-11 12:26:20 +00:00
STR_NETWORK_ENTER_IP ,
2008-09-15 16:29:40 +00:00
31 , // maximum number of characters
2008-05-11 12:26:20 +00:00
250 , // characters up to this width pixels, whichever is satisfied first
2008-09-15 16:29:40 +00:00
this , CS_ALPHANUMERAL , QSF_ACCEPT_UNCHANGED ) ;
2008-05-11 12:26:20 +00:00
break ;
2004-12-04 17:54:56 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_START : // Start server
ShowNetworkStartServerWindow ( ) ;
break ;
2004-12-04 17:54:56 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_JOIN : // Join Game
if ( this - > server ! = NULL ) {
2009-04-02 20:17:46 +00:00
snprintf ( _settings_client . network . last_host , sizeof ( _settings_client . network . last_host ) , " %s " , this - > server - > address . GetHostname ( ) ) ;
_settings_client . network . last_port = this - > server - > address . GetPort ( ) ;
2008-05-11 12:26:20 +00:00
ShowNetworkLobbyWindow ( this - > server ) ;
}
break ;
2004-08-09 17:04:08 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_REFRESH : // Refresh
2009-04-02 20:17:46 +00:00
if ( this - > server ! = NULL ) NetworkUDPQueryServer ( this - > server - > address ) ;
2008-05-11 12:26:20 +00:00
break ;
2006-01-26 17:10:11 +00:00
2008-05-11 12:26:20 +00:00
case NGWW_NEWGRF : // NewGRF Settings
if ( this - > server ! = NULL ) ShowNewGRFSettings ( false , false , false , & this - > server - > info . grfconfig ) ;
break ;
}
}
2007-07-27 19:57:52 +00:00
2008-08-31 20:54:01 +00:00
virtual void OnDoubleClick ( Point pt , int widget )
{
2008-09-02 17:24:46 +00:00
if ( widget = = NGWW_MATRIX | | widget = = NGWW_LASTJOINED ) {
2008-08-31 20:54:01 +00:00
/* is the Join button enabled? */
if ( ! this - > IsWidgetDisabled ( NGWW_JOIN ) ) this - > OnClick ( pt , NGWW_JOIN ) ;
}
}
2008-05-11 12:26:20 +00:00
virtual void OnDropdownSelect ( int widget , int index )
{
switch ( widget ) {
case NGWW_CONN_BTN :
2008-05-29 20:21:28 +00:00
_settings_client . network . lan_internet = index ;
2008-05-11 12:26:20 +00:00
break ;
2007-07-27 19:57:52 +00:00
2008-05-11 12:26:20 +00:00
default :
NOT_REACHED ( ) ;
}
this - > SetDirty ( ) ;
}
virtual void OnMouseLoop ( )
{
2008-09-30 20:39:50 +00:00
if ( this - > field = = NGWW_CLIENT ) this - > HandleEditBox ( NGWW_CLIENT ) ;
2008-05-11 12:26:20 +00:00
}
2007-11-25 15:17:16 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnInvalidateData ( int data )
{
2009-01-17 16:53:32 +00:00
switch ( data ) {
/* Remove the selection */
case 1 :
this - > server = NULL ;
this - > list_pos = SLP_INVALID ;
break ;
/* Reiterate the whole server list as we downloaded some files */
case 2 :
for ( NetworkGameList * * iter = this - > servers . Begin ( ) ; iter ! = this - > servers . End ( ) ; iter + + ) {
NetworkGameList * item = * iter ;
bool missing_grfs = false ;
for ( GRFConfig * c = item - > info . grfconfig ; c ! = NULL ; c = c - > next ) {
if ( c - > status ! = GCS_NOT_FOUND ) continue ;
const GRFConfig * f = FindGRFConfig ( c - > grfid , c - > md5sum ) ;
if ( f = = NULL ) {
missing_grfs = true ;
continue ;
}
c - > filename = f - > filename ;
c - > name = f - > name ;
c - > info = f - > info ;
c - > status = GCS_UNKNOWN ;
}
if ( ! missing_grfs ) item - > info . compatible = item - > info . version_compatible ;
}
break ;
2008-10-22 20:22:18 +00:00
}
2008-05-29 16:37:26 +00:00
this - > servers . ForceRebuild ( ) ;
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
}
2007-07-27 19:57:52 +00:00
2008-05-17 23:11:06 +00:00
virtual EventState OnKeyPress ( uint16 key , uint16 keycode )
2008-05-11 12:26:20 +00:00
{
2008-05-17 23:11:06 +00:00
EventState state = ES_NOT_HANDLED ;
2008-10-22 20:22:18 +00:00
/* handle up, down, pageup, pagedown, home and end */
2009-01-09 22:48:57 +00:00
if ( keycode = = WKC_UP | | keycode = = WKC_DOWN | | keycode = = WKC_PAGEUP | | keycode = = WKC_PAGEDOWN | | keycode = = WKC_HOME | | keycode = = WKC_END ) {
2008-10-22 20:22:18 +00:00
if ( this - > servers . Length ( ) = = 0 ) return ES_HANDLED ;
switch ( keycode ) {
case WKC_UP :
/* scroll up by one */
if ( this - > server = = NULL ) return ES_HANDLED ;
if ( this - > list_pos > 0 ) this - > list_pos - - ;
break ;
case WKC_DOWN :
/* scroll down by one */
if ( this - > server = = NULL ) return ES_HANDLED ;
if ( this - > list_pos < this - > servers . Length ( ) - 1 ) this - > list_pos + + ;
break ;
case WKC_PAGEUP :
/* scroll up a page */
if ( this - > server = = NULL ) return ES_HANDLED ;
this - > list_pos = ( this - > list_pos < this - > vscroll . cap ) ? 0 : this - > list_pos - this - > vscroll . cap ;
break ;
case WKC_PAGEDOWN :
/* scroll down a page */
if ( this - > server = = NULL ) return ES_HANDLED ;
2009-01-03 19:39:22 +00:00
this - > list_pos = min ( this - > list_pos + this - > vscroll . cap , ( int ) this - > servers . Length ( ) - 1 ) ;
2008-10-22 20:22:18 +00:00
break ;
case WKC_HOME :
/* jump to beginning */
this - > list_pos = 0 ;
break ;
case WKC_END :
/* jump to end */
this - > list_pos = this - > servers . Length ( ) - 1 ;
break ;
default : break ;
}
2009-01-09 22:48:57 +00:00
this - > server = this - > servers [ this - > list_pos ] ;
2008-10-22 20:22:18 +00:00
2009-01-09 22:48:57 +00:00
/* scroll to the new server if it is outside the current range */
this - > ScrollToSelectedServer ( ) ;
2008-10-22 20:22:18 +00:00
2009-01-09 22:48:57 +00:00
/* redraw window */
this - > SetDirty ( ) ;
return ES_HANDLED ;
}
2008-10-22 20:22:18 +00:00
2008-09-30 20:39:50 +00:00
if ( this - > field ! = NGWW_CLIENT ) {
2008-05-11 12:26:20 +00:00
if ( this - > server ! = NULL ) {
if ( keycode = = WKC_DELETE ) { // Press 'delete' to remove servers
NetworkGameListRemoveItem ( this - > server ) ;
NetworkRebuildHostList ( ) ;
this - > server = NULL ;
2008-10-22 20:22:18 +00:00
this - > list_pos = SLP_INVALID ;
2008-05-11 12:26:20 +00:00
}
2008-03-26 10:38:31 +00:00
}
2008-05-17 23:11:06 +00:00
return state ;
2008-05-11 12:26:20 +00:00
}
2007-07-27 19:57:52 +00:00
2008-10-25 19:59:11 +00:00
if ( this - > HandleEditBoxKey ( NGWW_CLIENT , key , keycode , state ) = = HEBR_CONFIRM ) return state ;
2008-05-11 12:26:20 +00:00
/* The name is only allowed when it starts with a letter! */
2008-05-29 17:01:42 +00:00
if ( ! StrEmpty ( this - > edit_str_buf ) & & this - > edit_str_buf [ 0 ] ! = ' ' ) {
2008-11-02 11:20:15 +00:00
strecpy ( _settings_client . network . client_name , this - > edit_str_buf , lastof ( _settings_client . network . client_name ) ) ;
2008-05-11 12:26:20 +00:00
} else {
2008-11-02 11:20:15 +00:00
strecpy ( _settings_client . network . client_name , " Player " , lastof ( _settings_client . network . client_name ) ) ;
2008-05-11 12:26:20 +00:00
}
2008-05-17 23:11:06 +00:00
return state ;
2004-08-09 17:04:08 +00:00
}
2008-05-11 12:26:20 +00:00
virtual void OnQueryTextFinished ( char * str )
{
if ( ! StrEmpty ( str ) ) {
NetworkAddServer ( str ) ;
NetworkRebuildHostList ( ) ;
}
}
2009-03-29 09:49:11 +00:00
virtual void OnResize ( Point delta )
2008-05-11 12:26:20 +00:00
{
this - > vscroll . cap + = delta . y / ( int ) this - > resize . step_height ;
this - > widget [ NGWW_MATRIX ] . data = ( this - > vscroll . cap < < 8 ) + 1 ;
2008-05-26 16:23:23 +00:00
SetVScrollCount ( this , this - > servers . Length ( ) ) ;
2008-05-11 12:26:20 +00:00
2008-07-18 20:44:35 +00:00
/* Additional colums in server list */
2009-03-14 18:16:29 +00:00
if ( this - > width > NetworkGameWindow : : MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth ( NGWW_MAPSIZE ) +
GetWidgetWidth ( NGWW_DATE ) + GetWidgetWidth ( NGWW_YEARS ) ) {
2008-07-18 20:44:35 +00:00
/* show columns 'Map size', 'Date' and 'Years' */
this - > SetWidgetsHiddenState ( false , NGWW_MAPSIZE , NGWW_DATE , NGWW_YEARS , WIDGET_LIST_END ) ;
AlignWidgetRight ( NGWW_YEARS , NGWW_INFO ) ;
AlignWidgetRight ( NGWW_DATE , NGWW_YEARS ) ;
AlignWidgetRight ( NGWW_MAPSIZE , NGWW_DATE ) ;
AlignWidgetRight ( NGWW_CLIENTS , NGWW_MAPSIZE ) ;
} else if ( this - > width > NetworkGameWindow : : MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth ( NGWW_MAPSIZE ) + GetWidgetWidth ( NGWW_DATE ) ) {
/* show columns 'Map size' and 'Date' */
this - > SetWidgetsHiddenState ( false , NGWW_MAPSIZE , NGWW_DATE , WIDGET_LIST_END ) ;
this - > HideWidget ( NGWW_YEARS ) ;
AlignWidgetRight ( NGWW_DATE , NGWW_INFO ) ;
AlignWidgetRight ( NGWW_MAPSIZE , NGWW_DATE ) ;
AlignWidgetRight ( NGWW_CLIENTS , NGWW_MAPSIZE ) ;
} else if ( this - > width > NetworkGameWindow : : MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth ( NGWW_MAPSIZE ) ) {
/* show column 'Map size' */
this - > ShowWidget ( NGWW_MAPSIZE ) ;
this - > SetWidgetsHiddenState ( true , NGWW_DATE , NGWW_YEARS , WIDGET_LIST_END ) ;
AlignWidgetRight ( NGWW_MAPSIZE , NGWW_INFO ) ;
AlignWidgetRight ( NGWW_CLIENTS , NGWW_MAPSIZE ) ;
} else {
/* hide columns 'Map size', 'Date' and 'Years' */
this - > SetWidgetsHiddenState ( true , NGWW_MAPSIZE , NGWW_DATE , NGWW_YEARS , WIDGET_LIST_END ) ;
AlignWidgetRight ( NGWW_CLIENTS , NGWW_INFO ) ;
}
this - > widget [ NGWW_NAME ] . right = this - > widget [ NGWW_CLIENTS ] . left - 1 ;
/* BOTTOM */
2008-05-11 12:26:20 +00:00
int widget_width = this - > widget [ NGWW_FIND ] . right - this - > widget [ NGWW_FIND ] . left ;
int space = ( this - > width - 4 * widget_width - 25 ) / 3 ;
int offset = 10 ;
for ( uint i = 0 ; i < 4 ; i + + ) {
this - > widget [ NGWW_FIND + i ] . left = offset ;
offset + = widget_width ;
this - > widget [ NGWW_FIND + i ] . right = offset ;
offset + = space ;
}
}
2008-07-18 20:44:35 +00:00
static const int MIN_EXTRA_COLUMNS_WIDTH = 550 ; ///< default width of the window
2008-05-11 12:26:20 +00:00
} ;
2004-08-09 17:04:08 +00:00
2008-07-18 20:44:35 +00:00
Listing NetworkGameWindow : : last_sorting = { false , 5 } ;
2009-03-15 16:04:39 +00:00
GUIGameServerList : : SortFunction * const NetworkGameWindow : : sorter_funcs [ ] = {
2008-05-29 16:37:26 +00:00
& NGameNameSorter ,
& NGameClientSorter ,
2008-07-18 20:44:35 +00:00
& NGameMapSizeSorter ,
& NGameDateSorter ,
& NGameYearsSorter ,
2008-05-29 16:37:26 +00:00
& NGameAllowedSorter
} ;
2004-08-09 17:04:08 +00:00
static const Widget _network_game_window_widgets [ ] = {
2007-11-24 21:41:59 +00:00
/* TOP */
2009-04-21 23:40:56 +00:00
{ WWT_CLOSEBOX , RESIZE_NONE , COLOUR_LIGHT_BLUE , 0 , 10 , 0 , 13 , STR_BLACK_CROSS , STR_TOOLTIP_CLOSE_WINDOW } , // NGWW_CLOSE
2008-08-03 02:18:45 +00:00
{ WWT_CAPTION , RESIZE_RIGHT , COLOUR_LIGHT_BLUE , 11 , 449 , 0 , 13 , STR_NETWORK_MULTIPLAYER , STR_NULL } , // NGWW_CAPTION
2009-03-15 15:22:09 +00:00
{ WWT_PANEL , RESIZE_RB , COLOUR_LIGHT_BLUE , 0 , 449 , 14 , 263 , 0x0 , STR_NULL } , // NGWW_MAIN
2004-12-04 17:54:56 +00:00
2008-08-03 02:18:45 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 9 , 85 , 23 , 35 , STR_NETWORK_CONNECTION , STR_NULL } , // NGWW_CONNECTION
2009-03-23 00:08:59 +00:00
{ WWT_DROPDOWN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 90 , 181 , 22 , 33 , STR_NETWORK_LAN_INTERNET_COMBO , STR_NETWORK_CONNECTION_TIP } , // NGWW_CONN_BTN
2004-12-22 18:42:56 +00:00
2008-09-30 20:39:50 +00:00
{ WWT_EDITBOX , RESIZE_LR , COLOUR_LIGHT_BLUE , 290 , 440 , 22 , 33 , STR_NETWORK_PLAYER_NAME_OSKTITLE , STR_NETWORK_ENTER_NAME_TIP } , // NGWW_CLIENT
2004-08-09 17:04:08 +00:00
2007-11-24 21:41:59 +00:00
/* LEFT SIDE */
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 10 , 70 , 42 , 53 , STR_NETWORK_GAME_NAME , STR_NETWORK_GAME_NAME_TIP } , // NGWW_NAME
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 71 , 150 , 42 , 53 , STR_NETWORK_CLIENTS_CAPTION , STR_NETWORK_CLIENTS_CAPTION_TIP } , // NGWW_CLIENTS
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 71 , 150 , 42 , 53 , STR_NETWORK_MAP_SIZE_CAPTION , STR_NETWORK_MAP_SIZE_CAPTION_TIP } , // NGWW_MAPSIZE
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 71 , 130 , 42 , 53 , STR_NETWORK_DATE_CAPTION , STR_NETWORK_DATE_CAPTION_TIP } , // NGWW_DATE
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 71 , 130 , 42 , 53 , STR_NETWORK_YEARS_CAPTION , STR_NETWORK_YEARS_CAPTION_TIP } , // NGWW_YEARS
{ WWT_PUSHTXTBTN , RESIZE_LR , COLOUR_WHITE , 151 , 190 , 42 , 53 , STR_EMPTY , STR_NETWORK_INFO_ICONS_TIP } , // NGWW_INFO
{ WWT_MATRIX , RESIZE_RB , COLOUR_LIGHT_BLUE , 10 , 190 , 54 , 208 , ( 11 < < 8 ) + 1 , STR_NETWORK_CLICK_GAME_TO_SELECT } , // NGWW_MATRIX
2009-04-21 23:40:56 +00:00
{ WWT_SCROLLBAR , RESIZE_LRB , COLOUR_LIGHT_BLUE , 191 , 202 , 42 , 208 , 0x0 , STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST } , // NGWW_SCROLLBAR
2008-08-03 02:18:45 +00:00
{ WWT_TEXT , RESIZE_RTB , COLOUR_LIGHT_BLUE , 10 , 190 , 211 , 222 , STR_NETWORK_LAST_JOINED_SERVER , STR_NULL } , // NGWW_LASTJOINED_LABEL
{ WWT_PANEL , RESIZE_RTB , COLOUR_LIGHT_BLUE , 10 , 190 , 223 , 236 , 0x0 , STR_NETWORK_CLICK_TO_SELECT_LAST } , // NGWW_LASTJOINED
2004-08-09 17:04:08 +00:00
2004-12-04 17:54:56 +00:00
/* RIGHT SIDE */
2008-08-03 02:18:45 +00:00
{ WWT_PANEL , RESIZE_LRB , COLOUR_LIGHT_BLUE , 210 , 440 , 42 , 236 , 0x0 , STR_NULL } , // NGWW_DETAILS
2007-07-27 19:57:52 +00:00
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_LRTB , COLOUR_WHITE , 215 , 315 , 215 , 226 , STR_NETWORK_JOIN_GAME , STR_NULL } , // NGWW_JOIN
{ WWT_PUSHTXTBTN , RESIZE_LRTB , COLOUR_WHITE , 330 , 435 , 215 , 226 , STR_NETWORK_REFRESH , STR_NETWORK_REFRESH_TIP } , // NGWW_REFRESH
2006-12-18 12:26:55 +00:00
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_LRTB , COLOUR_WHITE , 330 , 435 , 197 , 208 , STR_NEWGRF_SETTINGS_BUTTON , STR_NULL } , // NGWW_NEWGRF
2004-12-04 17:54:56 +00:00
2007-11-24 21:41:59 +00:00
/* BOTTOM */
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_TB , COLOUR_WHITE , 10 , 110 , 246 , 257 , STR_NETWORK_FIND_SERVER , STR_NETWORK_FIND_SERVER_TIP } , // NGWW_FIND
{ WWT_PUSHTXTBTN , RESIZE_TB , COLOUR_WHITE , 118 , 218 , 246 , 257 , STR_NETWORK_ADD_SERVER , STR_NETWORK_ADD_SERVER_TIP } , // NGWW_ADD
{ WWT_PUSHTXTBTN , RESIZE_TB , COLOUR_WHITE , 226 , 326 , 246 , 257 , STR_NETWORK_START_SERVER , STR_NETWORK_START_SERVER_TIP } , // NGWW_START
2009-04-21 23:40:56 +00:00
{ WWT_PUSHTXTBTN , RESIZE_TB , COLOUR_WHITE , 334 , 434 , 246 , 257 , STR_QUERY_CANCEL , STR_NULL } , // NGWW_CANCEL
2006-01-25 19:03:50 +00:00
2009-03-15 15:22:09 +00:00
{ WWT_RESIZEBOX , RESIZE_LRTB , COLOUR_LIGHT_BLUE , 438 , 449 , 252 , 263 , 0x0 , STR_RESIZE_BUTTON } , // NGWW_RESIZE
2004-08-09 17:04:08 +00:00
2004-09-07 21:48:09 +00:00
{ WIDGETS_END } ,
2004-08-09 17:04:08 +00:00
} ;
2009-03-22 21:16:57 +00:00
/* Generates incorrect display_flags for widgets NGWW_NAME, and incorrect
* display_flags and / or left / right side for the overlapping widgets
* NGWW_CLIENTS through NGWW_YEARS .
*/
NWidgetPart _nested_network_game_widgets [ ] = {
/* TOP */
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_LIGHT_BLUE , NGWW_CLOSE ) ,
NWidget ( WWT_CAPTION , COLOUR_LIGHT_BLUE , NGWW_CAPTION ) , SetMinimalSize ( 439 , 14 ) , SetDataTip ( STR_NETWORK_MULTIPLAYER , STR_NULL ) , // XXX Add default caption tooltip!
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NGWW_MAIN ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 8 ) , SetResize ( 1 , 0 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 9 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) , // Text is one pixel further down
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NGWW_CONNECTION ) , SetMinimalSize ( 77 , 13 ) , SetDataTip ( STR_NETWORK_CONNECTION , STR_NULL ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 4 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
2009-03-23 00:08:59 +00:00
NWidget ( WWT_DROPDOWN , COLOUR_LIGHT_BLUE , NGWW_CONN_BTN ) , SetMinimalSize ( 92 , 12 ) ,
2009-03-22 21:16:57 +00:00
SetDataTip ( STR_NETWORK_LAN_INTERNET_COMBO , STR_NETWORK_CONNECTION_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) , // Text ends two pixels further down
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 108 , 0 ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_EDITBOX , COLOUR_LIGHT_BLUE , NGWW_CLIENT ) , SetMinimalSize ( 151 , 12 ) ,
SetDataTip ( STR_NETWORK_PLAYER_NAME_OSKTITLE , STR_NETWORK_ENTER_NAME_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) , // Text ends two pixels further down
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 9 , 0 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) , SetResize ( 1 , 0 ) ,
NWidget ( NWID_HORIZONTAL ) ,
/* LEFT SIDE */
NWidget ( NWID_SPACER ) , SetMinimalSize ( 10 , 0 ) , SetResize ( 0 , 1 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_NAME ) , SetMinimalSize ( 61 , 12 ) , SetResize ( 1 , 0 ) ,
SetDataTip ( STR_NETWORK_GAME_NAME , STR_NETWORK_GAME_NAME_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_CLIENTS ) , SetMinimalSize ( 20 , 12 ) ,
SetDataTip ( STR_NETWORK_CLIENTS_CAPTION , STR_NETWORK_CLIENTS_CAPTION_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_MAPSIZE ) , SetMinimalSize ( 20 , 12 ) ,
SetDataTip ( STR_NETWORK_MAP_SIZE_CAPTION , STR_NETWORK_MAP_SIZE_CAPTION_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_DATE ) , SetMinimalSize ( 20 , 12 ) , SetDataTip ( STR_NETWORK_DATE_CAPTION , STR_NETWORK_DATE_CAPTION_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_YEARS ) , SetMinimalSize ( 20 , 12 ) , SetDataTip ( STR_NETWORK_YEARS_CAPTION , STR_NETWORK_YEARS_CAPTION_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 0 ) , SetFill ( 0 , 0 ) , SetResize ( 1 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_INFO ) , SetMinimalSize ( 40 , 12 ) , SetDataTip ( STR_EMPTY , STR_NETWORK_INFO_ICONS_TIP ) ,
EndContainer ( ) ,
NWidget ( WWT_MATRIX , COLOUR_LIGHT_BLUE , NGWW_MATRIX ) , SetMinimalSize ( 181 , 155 ) , SetResize ( 1 , 1 ) ,
SetDataTip ( ( 11 < < 8 ) + 1 , STR_NETWORK_CLICK_GAME_TO_SELECT ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) , SetResize ( 1 , 0 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NGWW_LASTJOINED_LABEL ) , SetMinimalSize ( 181 , 12 ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_NETWORK_LAST_JOINED_SERVER , STR_NULL ) , SetResize ( 1 , 0 ) ,
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NGWW_LASTJOINED ) , SetMinimalSize ( 181 , 14 ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
SetDataTip ( 0x0 , STR_NETWORK_CLICK_TO_SELECT_LAST ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_SCROLLBAR , COLOUR_LIGHT_BLUE , NGWW_SCROLLBAR ) , SetMinimalSize ( 12 , 165 ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 28 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 7 , 0 ) , SetResize ( 0 , 1 ) ,
/* RIGHT SIDE */
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NGWW_DETAILS ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 155 ) , SetResize ( 0 , 1 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 120 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_NEWGRF ) , SetMinimalSize ( 106 , 12 ) , SetDataTip ( STR_NEWGRF_SETTINGS_BUTTON , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 5 , 0 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 5 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_JOIN ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_JOIN_GAME , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 14 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_REFRESH ) , SetMinimalSize ( 106 , 12 ) , SetDataTip ( STR_NETWORK_REFRESH , STR_NETWORK_REFRESH_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 5 , 0 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 10 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 9 , 0 ) , SetResize ( 0 , 1 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 9 ) , SetResize ( 1 , 0 ) ,
/* BOTTOM */
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 10 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_FIND ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_FIND_SERVER , STR_NETWORK_FIND_SERVER_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 7 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_ADD ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_ADD_SERVER , STR_NETWORK_ADD_SERVER_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 7 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_START ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_START_SERVER , STR_NETWORK_START_SERVER_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 7 , 0 ) ,
2009-04-21 23:40:56 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NGWW_CANCEL ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_QUERY_CANCEL , STR_NULL ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 3 , 0 ) , SetResize ( 1 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_RESIZEBOX , COLOUR_LIGHT_BLUE , NGWW_RESIZE ) ,
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _network_game_window_desc (
2008-07-18 20:44:35 +00:00
WDP_CENTER , WDP_CENTER , 450 , 264 , 780 , 264 ,
2007-02-01 15:49:12 +00:00
WC_NETWORK_WINDOW , WC_NONE ,
2007-07-27 19:57:52 +00:00
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE ,
2009-03-22 21:16:57 +00:00
_network_game_window_widgets , _nested_network_game_widgets , lengthof ( _nested_network_game_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2007-03-07 11:47:46 +00:00
void ShowNetworkGameWindow ( )
2004-08-09 17:04:08 +00:00
{
2006-01-29 20:24:18 +00:00
static bool first = true ;
2004-08-09 17:04:08 +00:00
DeleteWindowById ( WC_NETWORK_WINDOW , 0 ) ;
2004-08-22 10:23:37 +00:00
2004-12-22 18:42:56 +00:00
/* Only show once */
2006-01-29 20:24:18 +00:00
if ( first ) {
first = false ;
2009-03-15 00:32:18 +00:00
/* add all servers from the config file to our list */
2009-04-03 12:49:58 +00:00
for ( char * * iter = _network_host_list . Begin ( ) ; iter ! = _network_host_list . End ( ) ; iter + + ) {
NetworkAddServer ( * iter ) ;
}
2004-12-22 18:42:56 +00:00
}
2008-05-11 12:26:20 +00:00
new NetworkGameWindow ( & _network_game_window_desc ) ;
2004-12-04 17:54:56 +00:00
}
enum {
NSSWND_START = 64 ,
NSSWND_ROWSIZE = 12
} ;
2007-11-24 18:09:02 +00:00
/** Enum for NetworkStartServerWindow, referring to _network_start_server_window_widgets */
enum NetworkStartServerWidgets {
2009-05-05 20:36:16 +00:00
NSSW_CLOSE , ///< Close 'X' button
NSSW_CAPTION ,
NSSW_BACKGROUND ,
NSSW_GAMENAME_LABEL ,
NSSW_GAMENAME , ///< Background for editbox to set game name
NSSW_SETPWD , ///< 'Set password' button
NSSW_SELECT_MAP_LABEL ,
NSSW_SELMAP , ///< 'Select map' list
NSSW_SCROLLBAR ,
NSSW_CONNTYPE_LABEL ,
NSSW_CONNTYPE_BTN , ///< 'Connection type' droplist button
NSSW_CLIENTS_LABEL ,
NSSW_CLIENTS_BTND , ///< 'Max clients' downarrow
NSSW_CLIENTS_TXT , ///< 'Max clients' text
NSSW_CLIENTS_BTNU , ///< 'Max clients' uparrow
NSSW_COMPANIES_LABEL ,
NSSW_COMPANIES_BTND , ///< 'Max companies' downarrow
NSSW_COMPANIES_TXT , ///< 'Max companies' text
NSSW_COMPANIES_BTNU , ///< 'Max companies' uparrow
NSSW_SPECTATORS_LABEL ,
NSSW_SPECTATORS_BTND , ///< 'Max spectators' downarrow
NSSW_SPECTATORS_TXT , ///< 'Max spectators' text
NSSW_SPECTATORS_BTNU , ///< 'Max spectators' uparrow
NSSW_LANGUAGE_LABEL ,
NSSW_LANGUAGE_BTN , ///< 'Language spoken' droplist button
NSSW_START , ///< 'Start' button
NSSW_LOAD , ///< 'Load' button
NSSW_CANCEL , ///< 'Cancel' button
2007-11-24 18:09:02 +00:00
} ;
2008-05-11 12:26:20 +00:00
struct NetworkStartServerWindow : public QueryStringBaseWindow {
byte field ; ///< Selected text-field
FiosItem * map ; ///< Selected map
byte widget_id ; ///< The widget that has the pop-up input menu
2006-01-26 16:19:24 +00:00
2008-08-11 22:08:56 +00:00
NetworkStartServerWindow ( const WindowDesc * desc ) : QueryStringBaseWindow ( NETWORK_NAME_LENGTH , desc )
2008-05-11 12:26:20 +00:00
{
2008-08-11 22:08:56 +00:00
ttd_strlcpy ( this - > edit_str_buf , _settings_client . network . server_name , this - > edit_str_size ) ;
2005-11-14 19:48:04 +00:00
2008-05-11 12:26:20 +00:00
_saveload_mode = SLD_NEW_GAME ;
BuildFileList ( ) ;
this - > vscroll . cap = 12 ;
2008-07-23 13:10:08 +00:00
this - > vscroll . count = _fios_items . Length ( ) + 1 ;
2005-07-17 16:01:26 +00:00
2008-05-11 12:26:20 +00:00
this - > afilter = CS_ALPHANUMERAL ;
2008-08-11 22:08:56 +00:00
InitializeTextBuffer ( & this - > text , this - > edit_str_buf , this - > edit_str_size , 160 ) ;
2009-02-09 01:22:29 +00:00
this - > SetFocusedWidget ( NSSW_GAMENAME ) ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
this - > field = NSSW_GAMENAME ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
this - > FindWindowPlacementAndResize ( desc ) ;
}
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnPaint ( )
{
2008-06-02 14:19:27 +00:00
int y = NSSWND_START ;
2008-05-11 12:26:20 +00:00
const FiosItem * item ;
/* draw basic widgets */
2008-06-09 12:17:01 +00:00
SetDParam ( 1 , _connection_types_dropdown [ _settings_client . network . server_advertise ] ) ;
2008-06-03 08:04:35 +00:00
SetDParam ( 2 , _settings_client . network . max_clients ) ;
SetDParam ( 3 , _settings_client . network . max_companies ) ;
SetDParam ( 4 , _settings_client . network . max_spectators ) ;
SetDParam ( 5 , STR_NETWORK_LANG_ANY + _settings_client . network . server_lang ) ;
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
/* editbox to set game name */
this - > DrawEditBox ( NSSW_GAMENAME ) ;
/* if password is set, draw red '*' next to 'Set password' button */
2009-03-21 22:46:17 +00:00
if ( ! StrEmpty ( _settings_client . network . server_password ) ) DrawString ( 408 , this - > width - 2 , 23 , " * " , TC_RED ) ;
2008-05-11 12:26:20 +00:00
/* draw list of maps */
2009-03-22 23:38:29 +00:00
GfxFillRect ( this - > widget [ NSSW_SELMAP ] . left + 1 , this - > widget [ NSSW_SELMAP ] . top + 1 , this - > widget [ NSSW_SELMAP ] . right - 1 , this - > widget [ NSSW_SELMAP ] . bottom - 1 , 0xD7 ) ; // black background of maps list
2008-03-26 10:38:31 +00:00
2008-06-02 14:19:27 +00:00
for ( uint pos = this - > vscroll . pos ; pos < _fios_items . Length ( ) + 1 ; pos + + ) {
item = _fios_items . Get ( pos - 1 ) ;
2009-03-22 23:38:29 +00:00
if ( item = = this - > map | | ( pos = = 0 & & this - > map = = NULL ) ) {
GfxFillRect ( this - > widget [ NSSW_SELMAP ] . left + 1 , y - 1 , this - > widget [ NSSW_SELMAP ] . right - 1 , y + 10 , 155 ) ; // show highlighted item with a different colour
}
2008-05-11 12:26:20 +00:00
if ( pos = = 0 ) {
2009-04-21 23:40:56 +00:00
DrawString ( this - > widget [ NSSW_SELMAP ] . left + 4 , this - > widget [ NSSW_SELMAP ] . right - 4 , y , STR_NETWORK_SERVER_RANDOM_GAME , TC_DARK_GREEN ) ;
2008-05-11 12:26:20 +00:00
} else {
2009-03-22 23:38:29 +00:00
DrawString ( this - > widget [ NSSW_SELMAP ] . left + 4 , this - > widget [ NSSW_SELMAP ] . right - 4 , y , item - > title , _fios_colours [ item - > type ] ) ;
2007-08-14 10:46:38 +00:00
}
2008-05-11 12:26:20 +00:00
y + = NSSWND_ROWSIZE ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
if ( y > = this - > vscroll . cap * NSSWND_ROWSIZE + NSSWND_START ) break ;
}
}
2005-07-17 16:01:26 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnClick ( Point pt , int widget )
{
this - > field = widget ;
switch ( widget ) {
case NSSW_CLOSE : // Close 'X'
case NSSW_CANCEL : // Cancel button
ShowNetworkGameWindow ( ) ;
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_SETPWD : // Set password button
this - > widget_id = NSSW_SETPWD ;
2008-07-17 13:47:04 +00:00
SetDParamStr ( 0 , _settings_client . network . server_password ) ;
2008-09-15 16:29:40 +00:00
ShowQueryString ( STR_JUST_RAW_STRING , STR_NETWORK_SET_PASSWORD , 20 , 250 , this , CS_ALPHANUMERAL , QSF_NONE ) ;
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_SELMAP : { // Select map
int y = ( pt . y - NSSWND_START ) / NSSWND_ROWSIZE ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
y + = this - > vscroll . pos ;
if ( y > = this - > vscroll . count ) return ;
2008-03-26 10:38:31 +00:00
2008-06-02 14:19:27 +00:00
this - > map = ( y = = 0 ) ? NULL : _fios_items . Get ( y - 1 ) ;
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
} break ;
case NSSW_CONNTYPE_BTN : // Connection type
2008-06-09 12:17:01 +00:00
ShowDropDownMenu ( this , _connection_types_dropdown , _settings_client . network . server_advertise , NSSW_CONNTYPE_BTN , 0 , 0 ) ; // do it for widget NSSW_CONNTYPE_BTN
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_CLIENTS_BTND : case NSSW_CLIENTS_BTNU : // Click on up/down button for number of clients
case NSSW_COMPANIES_BTND : case NSSW_COMPANIES_BTNU : // Click on up/down button for number of companies
case NSSW_SPECTATORS_BTND : case NSSW_SPECTATORS_BTNU : // Click on up/down button for number of spectators
/* Don't allow too fast scrolling */
2008-09-23 15:24:15 +00:00
if ( ( this - > flags4 & WF_TIMEOUT_MASK ) < = WF_TIMEOUT_TRIGGER ) {
2008-05-11 12:26:20 +00:00
this - > HandleButtonClick ( widget ) ;
this - > SetDirty ( ) ;
switch ( widget ) {
default : NOT_REACHED ( ) ;
case NSSW_CLIENTS_BTND : case NSSW_CLIENTS_BTNU :
2008-06-03 08:04:35 +00:00
_settings_client . network . max_clients = Clamp ( _settings_client . network . max_clients + widget - NSSW_CLIENTS_TXT , 2 , MAX_CLIENTS ) ;
2008-05-11 12:26:20 +00:00
break ;
case NSSW_COMPANIES_BTND : case NSSW_COMPANIES_BTNU :
2008-09-30 20:39:50 +00:00
_settings_client . network . max_companies = Clamp ( _settings_client . network . max_companies + widget - NSSW_COMPANIES_TXT , 1 , MAX_COMPANIES ) ;
2008-05-11 12:26:20 +00:00
break ;
case NSSW_SPECTATORS_BTND : case NSSW_SPECTATORS_BTNU :
2008-06-03 08:04:35 +00:00
_settings_client . network . max_spectators = Clamp ( _settings_client . network . max_spectators + widget - NSSW_SPECTATORS_TXT , 0 , MAX_CLIENTS ) ;
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
}
2008-05-11 12:26:20 +00:00
}
_left_button_clicked = false ;
break ;
2008-03-26 10:38:31 +00:00
2008-09-30 20:39:50 +00:00
case NSSW_CLIENTS_TXT : // Click on number of clients
2008-05-11 12:26:20 +00:00
this - > widget_id = NSSW_CLIENTS_TXT ;
2008-06-03 08:04:35 +00:00
SetDParam ( 0 , _settings_client . network . max_clients ) ;
2009-02-08 12:25:13 +00:00
ShowQueryString ( STR_CONFIG_SETTING_INT32 , STR_NETWORK_NUMBER_OF_CLIENTS , 4 , 50 , this , CS_NUMERAL , QSF_NONE ) ;
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_COMPANIES_TXT : // Click on number of companies
this - > widget_id = NSSW_COMPANIES_TXT ;
2008-06-03 08:04:35 +00:00
SetDParam ( 0 , _settings_client . network . max_companies ) ;
2009-02-08 12:25:13 +00:00
ShowQueryString ( STR_CONFIG_SETTING_INT32 , STR_NETWORK_NUMBER_OF_COMPANIES , 3 , 50 , this , CS_NUMERAL , QSF_NONE ) ;
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_SPECTATORS_TXT : // Click on number of spectators
this - > widget_id = NSSW_SPECTATORS_TXT ;
2008-06-03 08:04:35 +00:00
SetDParam ( 0 , _settings_client . network . max_spectators ) ;
2009-02-08 12:25:13 +00:00
ShowQueryString ( STR_CONFIG_SETTING_INT32 , STR_NETWORK_NUMBER_OF_SPECTATORS , 4 , 50 , this , CS_NUMERAL , QSF_NONE ) ;
2008-05-11 12:26:20 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_LANGUAGE_BTN : { // Language
uint sel = 0 ;
for ( uint i = 0 ; i < lengthof ( _language_dropdown ) - 1 ; i + + ) {
2008-06-03 08:04:35 +00:00
if ( _language_dropdown [ i ] = = STR_NETWORK_LANG_ANY + _settings_client . network . server_lang ) {
2008-05-11 12:26:20 +00:00
sel = i ;
break ;
2008-03-26 10:38:31 +00:00
}
2008-05-11 12:26:20 +00:00
}
ShowDropDownMenu ( this , _language_dropdown , sel , NSSW_LANGUAGE_BTN , 0 , 0 ) ;
} break ;
case NSSW_START : // Start game
_is_network_server = true ;
if ( this - > map = = NULL ) { // start random new game
ShowGenerateLandscape ( ) ;
} else { // load a scenario
2009-03-04 00:13:52 +00:00
const char * name = FiosBrowseTo ( this - > map ) ;
2008-05-11 12:26:20 +00:00
if ( name ! = NULL ) {
SetFiosType ( this - > map - > type ) ;
_file_to_saveload . filetype = FT_SCENARIO ;
2008-11-02 11:20:15 +00:00
strecpy ( _file_to_saveload . name , name , lastof ( _file_to_saveload . name ) ) ;
strecpy ( _file_to_saveload . title , this - > map - > title , lastof ( _file_to_saveload . title ) ) ;
2008-05-11 12:26:20 +00:00
delete this ;
2009-02-25 00:45:52 +00:00
SwitchToMode ( SM_START_SCENARIO ) ;
2008-03-26 10:38:31 +00:00
}
2008-05-11 12:26:20 +00:00
}
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 12:26:20 +00:00
case NSSW_LOAD : // Load game
_is_network_server = true ;
/* XXX - WC_NETWORK_WINDOW (this window) should stay, but if it stays, it gets
2009-03-14 18:16:29 +00:00
* copied all the elements of ' load game ' and upon closing that , it segfaults */
2008-05-11 12:26:20 +00:00
delete this ;
ShowSaveLoadDialog ( SLD_LOAD_GAME ) ;
break ;
}
}
2004-09-06 22:46:02 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnDropdownSelect ( int widget , int index )
{
switch ( widget ) {
case NSSW_CONNTYPE_BTN :
2008-06-09 12:17:01 +00:00
_settings_client . network . server_advertise = ( index ! = 0 ) ;
2008-05-11 12:26:20 +00:00
break ;
case NSSW_LANGUAGE_BTN :
2008-06-03 08:04:35 +00:00
_settings_client . network . server_lang = _language_dropdown [ index ] - STR_NETWORK_LANG_ANY ;
2008-05-11 12:26:20 +00:00
break ;
default :
NOT_REACHED ( ) ;
}
2004-09-06 22:46:02 +00:00
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
}
2004-09-06 22:46:02 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnMouseLoop ( )
{
if ( this - > field = = NSSW_GAMENAME ) this - > HandleEditBox ( NSSW_GAMENAME ) ;
}
2004-08-09 17:04:08 +00:00
2008-05-17 23:11:06 +00:00
virtual EventState OnKeyPress ( uint16 key , uint16 keycode )
2008-05-11 12:26:20 +00:00
{
2008-05-17 23:11:06 +00:00
EventState state = ES_NOT_HANDLED ;
2008-05-11 12:26:20 +00:00
if ( this - > field = = NSSW_GAMENAME ) {
2008-10-25 19:59:11 +00:00
if ( this - > HandleEditBoxKey ( NSSW_GAMENAME , key , keycode , state ) = = HEBR_CONFIRM ) return state ;
2006-01-26 16:19:24 +00:00
2008-11-02 11:20:15 +00:00
strecpy ( _settings_client . network . server_name , this - > text . buf , lastof ( _settings_client . network . server_name ) ) ;
2008-05-11 12:26:20 +00:00
}
2004-09-10 19:02:27 +00:00
2008-05-17 23:11:06 +00:00
return state ;
2008-05-11 12:26:20 +00:00
}
2007-08-14 10:46:38 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnQueryTextFinished ( char * str )
{
if ( str = = NULL ) return ;
if ( this - > widget_id = = NSSW_SETPWD ) {
2008-11-02 11:20:15 +00:00
strecpy ( _settings_client . network . server_password , str , lastof ( _settings_client . network . server_password ) ) ;
2008-05-11 12:26:20 +00:00
} else {
int32 value = atoi ( str ) ;
this - > InvalidateWidget ( this - > widget_id ) ;
switch ( this - > widget_id ) {
default : NOT_REACHED ( ) ;
2008-06-03 08:04:35 +00:00
case NSSW_CLIENTS_TXT : _settings_client . network . max_clients = Clamp ( value , 2 , MAX_CLIENTS ) ; break ;
2008-09-30 20:39:50 +00:00
case NSSW_COMPANIES_TXT : _settings_client . network . max_companies = Clamp ( value , 1 , MAX_COMPANIES ) ; break ;
2008-06-03 08:04:35 +00:00
case NSSW_SPECTATORS_TXT : _settings_client . network . max_spectators = Clamp ( value , 0 , MAX_CLIENTS ) ; break ;
2007-08-14 10:46:38 +00:00
}
2008-05-11 12:26:20 +00:00
}
2007-08-14 10:46:38 +00:00
2008-05-11 12:26:20 +00:00
this - > SetDirty ( ) ;
2004-08-09 17:04:08 +00:00
}
2008-05-11 12:26:20 +00:00
} ;
2004-08-09 17:04:08 +00:00
static const Widget _network_start_server_window_widgets [ ] = {
2007-11-24 18:09:02 +00:00
/* Window decoration and background panel */
2009-05-05 20:36:16 +00:00
{ WWT_CLOSEBOX , RESIZE_NONE , COLOUR_LIGHT_BLUE , 0 , 10 , 0 , 13 , STR_BLACK_CROSS , STR_TOOLTIP_CLOSE_WINDOW } , // NSSW_CLOSE
{ WWT_CAPTION , RESIZE_NONE , COLOUR_LIGHT_BLUE , 11 , 419 , 0 , 13 , STR_NETWORK_START_GAME_WINDOW , STR_NULL } , // NSSW_CAPTION
{ WWT_PANEL , RESIZE_NONE , COLOUR_LIGHT_BLUE , 0 , 419 , 14 , 243 , 0x0 , STR_NULL } , // NSSW_BACKGROUND
2007-11-24 18:09:02 +00:00
/* Set game name and password widgets */
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 10 , 90 , 22 , 34 , STR_NETWORK_NEW_GAME_NAME , STR_NULL } , // NSSW_GAMENAME_LABEL
2008-08-03 02:18:45 +00:00
{ WWT_EDITBOX , RESIZE_NONE , COLOUR_LIGHT_BLUE , 100 , 272 , 22 , 33 , STR_NETWORK_NEW_GAME_NAME_OSKTITLE , STR_NETWORK_NEW_GAME_NAME_TIP } , // NSSW_GAMENAME
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 285 , 405 , 22 , 33 , STR_NETWORK_SET_PASSWORD , STR_NETWORK_PASSWORD_TIP } , // NSSW_SETPWD
2007-08-14 10:46:38 +00:00
2007-11-24 18:09:02 +00:00
/* List of playable scenarios */
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 10 , 110 , 43 , 55 , STR_NETWORK_SELECT_MAP , STR_NULL } , // NSSW_SELECT_MAP_LABEL
2008-08-03 02:18:45 +00:00
{ WWT_INSET , RESIZE_NONE , COLOUR_LIGHT_BLUE , 10 , 271 , 62 , 216 , STR_NULL , STR_NETWORK_SELECT_MAP_TIP } , // NSSW_SELMAP
2009-05-05 20:36:16 +00:00
{ WWT_SCROLLBAR , RESIZE_NONE , COLOUR_LIGHT_BLUE , 259 , 270 , 63 , 215 , 0x0 , STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST } , // NSSW_SCROLLBAR
2007-08-14 10:46:38 +00:00
/* Combo/selection boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 63 , 75 , STR_NETWORK_CONNECTION , STR_NULL } , // NSSW_CONNTYPE_LABEL
2009-03-23 00:08:59 +00:00
{ WWT_DROPDOWN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 77 , 88 , STR_NETWORK_LAN_INTERNET_COMBO , STR_NETWORK_CONNECTION_TIP } , // NSSW_CONNTYPE_BTN
2007-11-24 18:09:02 +00:00
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 95 , 107 , STR_NETWORK_NUMBER_OF_CLIENTS , STR_NULL } , // NSSW_CLIENTS_LABEL
2008-08-03 02:18:45 +00:00
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 291 , 109 , 120 , SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_CLIENTS_TIP } , // NSSW_CLIENTS_BTND
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 292 , 397 , 109 , 120 , STR_NETWORK_CLIENTS_SELECT , STR_NETWORK_NUMBER_OF_CLIENTS_TIP } , // NSSW_CLIENTS_TXT
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 398 , 410 , 109 , 120 , SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_CLIENTS_TIP } , // NSSW_CLIENTS_BTNU
2007-11-24 18:09:02 +00:00
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 127 , 139 , STR_NETWORK_NUMBER_OF_COMPANIES , STR_NULL } , // NSSW_COMPANIES_LABEL
2008-08-03 02:18:45 +00:00
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 291 , 141 , 152 , SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_COMPANIES_TIP } , // NSSW_COMPANIES_BTND
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 292 , 397 , 141 , 152 , STR_NETWORK_COMPANIES_SELECT , STR_NETWORK_NUMBER_OF_COMPANIES_TIP } , // NSSW_COMPANIES_TXT
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 398 , 410 , 141 , 152 , SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_COMPANIES_TIP } , // NSSW_COMPANIES_BTNU
2007-11-24 18:09:02 +00:00
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 159 , 171 , STR_NETWORK_NUMBER_OF_SPECTATORS , STR_NULL } , // NSSW_SPECTATORS_LABEL
2008-08-03 02:18:45 +00:00
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 291 , 173 , 184 , SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP } , // NSSW_SPECTATORS_BTND
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 292 , 397 , 173 , 184 , STR_NETWORK_SPECTATORS_SELECT , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP } , // NSSW_SPECTATORS_TXT
{ WWT_IMGBTN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 398 , 410 , 173 , 184 , SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP } , // NSSW_SPECTATORS_BTNU
2007-11-24 18:09:02 +00:00
2009-05-05 20:36:16 +00:00
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 191 , 203 , STR_NETWORK_LANGUAGE_SPOKEN , STR_NULL } , // NSSW_LANGUAGE_LABEL
2009-03-23 00:08:59 +00:00
{ WWT_DROPDOWN , RESIZE_NONE , COLOUR_LIGHT_BLUE , 280 , 410 , 205 , 216 , STR_NETWORK_LANGUAGE_COMBO , STR_NETWORK_LANGUAGE_TIP } , // NSSW_LANGUAGE_BTN
2007-11-24 18:09:02 +00:00
/* Buttons Start / Load / Cancel */
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 40 , 140 , 224 , 235 , STR_NETWORK_START_GAME , STR_NETWORK_START_GAME_TIP } , // NSSW_START
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 150 , 250 , 224 , 235 , STR_NETWORK_LOAD_GAME , STR_NETWORK_LOAD_GAME_TIP } , // NSSW_LOAD
2009-04-21 23:40:56 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 260 , 360 , 224 , 235 , STR_QUERY_CANCEL , STR_NULL } , // NSSW_CANCEL
2007-11-24 18:09:02 +00:00
2004-09-07 21:48:09 +00:00
{ WIDGETS_END } ,
2004-08-09 17:04:08 +00:00
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_network_start_server_window_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_LIGHT_BLUE , NSSW_CLOSE ) ,
NWidget ( WWT_CAPTION , COLOUR_LIGHT_BLUE , NSSW_CAPTION ) , SetDataTip ( STR_NETWORK_START_GAME_WINDOW , STR_NULL ) ,
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NSSW_BACKGROUND ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 8 ) ,
/* Set game name and password widgets. */
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 10 , 0 , 14 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_GAMENAME_LABEL ) , SetMinimalSize ( 81 , 13 ) , SetDataTip ( STR_NETWORK_NEW_GAME_NAME , STR_NULL ) ,
NWidget ( WWT_EDITBOX , COLOUR_LIGHT_BLUE , NSSW_GAMENAME ) , SetMinimalSize ( 173 , 12 ) , SetPadding ( 0 , 0 , 1 , 9 ) ,
SetDataTip ( STR_NETWORK_NEW_GAME_NAME_OSKTITLE , STR_NETWORK_NEW_GAME_NAME_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NSSW_SETPWD ) , SetMinimalSize ( 121 , 12 ) , SetPadding ( 0 , 0 , 1 , 12 ) ,
SetDataTip ( STR_NETWORK_SET_PASSWORD , STR_NETWORK_PASSWORD_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 10 , 8 , 9 ) ,
NWidget ( NWID_VERTICAL ) ,
/* List of playable scenarios. */
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 8 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_SELECT_MAP_LABEL ) , SetMinimalSize ( 101 , 13 ) , SetDataTip ( STR_NETWORK_SELECT_MAP , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetFill ( true , false ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_INSET , COLOUR_LIGHT_BLUE , NSSW_SELMAP ) , SetDataTip ( STR_NULL , STR_NETWORK_SELECT_MAP_TIP ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 249 , 155 ) ,
NWidget ( WWT_SCROLLBAR , COLOUR_LIGHT_BLUE , NSSW_SCROLLBAR ) , SetPadding ( 1 , 1 , 1 , 0 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) ,
/* Combo/selection boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 28 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_CONNTYPE_LABEL ) , SetMinimalSize ( 131 , 13 ) , SetDataTip ( STR_NETWORK_CONNECTION , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) ,
NWidget ( WWT_DROPDOWN , COLOUR_LIGHT_BLUE , NSSW_CONNTYPE_BTN ) , SetMinimalSize ( 131 , 12 ) ,
SetDataTip ( STR_NETWORK_LAN_INTERNET_COMBO , STR_NETWORK_CONNECTION_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_CLIENTS_LABEL ) , SetMinimalSize ( 131 , 13 ) , SetDataTip ( STR_NETWORK_NUMBER_OF_CLIENTS , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_CLIENTS_BTND ) , SetMinimalSize ( 12 , 12 ) ,
SetDataTip ( SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_CLIENTS_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_LIGHT_BLUE , NSSW_CLIENTS_TXT ) , SetMinimalSize ( 106 , 12 ) ,
SetDataTip ( STR_NETWORK_CLIENTS_SELECT , STR_NETWORK_NUMBER_OF_CLIENTS_TIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_CLIENTS_BTNU ) , SetMinimalSize ( 13 , 12 ) ,
SetDataTip ( SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_CLIENTS_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_COMPANIES_LABEL ) , SetMinimalSize ( 131 , 13 ) , SetDataTip ( STR_NETWORK_NUMBER_OF_COMPANIES , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_COMPANIES_BTND ) , SetMinimalSize ( 12 , 12 ) ,
SetDataTip ( SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_COMPANIES_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_LIGHT_BLUE , NSSW_COMPANIES_TXT ) , SetMinimalSize ( 106 , 12 ) ,
SetDataTip ( STR_NETWORK_COMPANIES_SELECT , STR_NETWORK_NUMBER_OF_COMPANIES_TIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_COMPANIES_BTNU ) , SetMinimalSize ( 13 , 12 ) ,
SetDataTip ( SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_COMPANIES_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_SPECTATORS_LABEL ) , SetMinimalSize ( 131 , 13 ) , SetDataTip ( STR_NETWORK_NUMBER_OF_SPECTATORS , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_SPECTATORS_BTND ) , SetMinimalSize ( 12 , 12 ) ,
SetDataTip ( SPR_ARROW_DOWN , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_LIGHT_BLUE , NSSW_SPECTATORS_TXT ) , SetMinimalSize ( 106 , 12 ) ,
SetDataTip ( STR_NETWORK_SPECTATORS_SELECT , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_LIGHT_BLUE , NSSW_SPECTATORS_BTNU ) , SetMinimalSize ( 13 , 12 ) ,
SetDataTip ( SPR_ARROW_UP , STR_NETWORK_NUMBER_OF_SPECTATORS_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 6 ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NSSW_LANGUAGE_LABEL ) , SetMinimalSize ( 131 , 13 ) , SetDataTip ( STR_NETWORK_LANGUAGE_SPOKEN , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 1 ) ,
NWidget ( WWT_DROPDOWN , COLOUR_LIGHT_BLUE , NSSW_LANGUAGE_BTN ) , SetMinimalSize ( 131 , 12 ) ,
SetDataTip ( STR_NETWORK_LANGUAGE_COMBO , STR_NETWORK_LANGUAGE_TIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
/* Buttons Start / Load / Cancel. */
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 7 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 40 , 9 , 59 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NSSW_START ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_START_GAME , STR_NETWORK_START_GAME_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NSSW_LOAD ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_NETWORK_LOAD_GAME , STR_NETWORK_LOAD_GAME_TIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NSSW_CANCEL ) , SetMinimalSize ( 101 , 12 ) , SetDataTip ( STR_QUERY_CANCEL , STR_NULL ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 8 ) ,
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _network_start_server_window_desc (
2007-07-27 12:49:04 +00:00
WDP_CENTER , WDP_CENTER , 420 , 244 , 420 , 244 ,
2007-02-01 15:49:12 +00:00
WC_NETWORK_WINDOW , WC_NONE ,
2005-07-15 15:09:52 +00:00
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS ,
2009-05-05 20:40:08 +00:00
_network_start_server_window_widgets , _nested_network_start_server_window_widgets , lengthof ( _nested_network_start_server_window_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2007-03-07 11:47:46 +00:00
static void ShowNetworkStartServerWindow ( )
2004-08-09 17:04:08 +00:00
{
DeleteWindowById ( WC_NETWORK_WINDOW , 0 ) ;
2004-09-10 19:02:27 +00:00
2008-05-11 12:26:20 +00:00
new NetworkStartServerWindow ( & _network_start_server_window_desc ) ;
2004-08-09 17:04:08 +00:00
}
2007-11-25 11:36:45 +00:00
/** Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets */
enum NetworkLobbyWindowWidgets {
2009-05-05 20:36:16 +00:00
NLWW_CLOSE , ///< Close 'X' button
NLWW_CAPTION , ///< Titlebar
NLWW_BACKGROUND , ///< Background panel
NLWW_TEXT , ///< Heading text
NLWW_HEADER , ///< Header above list of companies
NLWW_MATRIX , ///< List of companies
NLWW_SCROLLBAR , ///< Scroll bar
NLWW_DETAILS , ///< Company details
NLWW_JOIN , ///< 'Join company' button
NLWW_NEW , ///< 'New company' button
NLWW_SPECTATE , ///< 'Spectate game' button
NLWW_REFRESH , ///< 'Refresh server' button
NLWW_CANCEL , ///< 'Cancel' button
2007-11-25 11:36:45 +00:00
} ;
2008-05-11 07:22:13 +00:00
struct NetworkLobbyWindow : public Window {
2008-09-30 20:39:50 +00:00
CompanyID company ; ///< Select company
2008-05-11 07:22:13 +00:00
NetworkGameList * server ; ///< Selected server
2008-12-22 18:40:57 +00:00
NetworkCompanyInfo company_info [ MAX_COMPANIES ] ;
2004-08-09 17:04:08 +00:00
2008-05-11 07:22:13 +00:00
NetworkLobbyWindow ( const WindowDesc * desc , NetworkGameList * ngl ) :
2008-09-30 20:39:50 +00:00
Window ( desc ) , company ( INVALID_COMPANY ) , server ( ngl )
2008-05-11 07:22:13 +00:00
{
this - > vscroll . cap = 10 ;
2008-05-11 11:41:18 +00:00
this - > FindWindowPlacementAndResize ( desc ) ;
2008-05-11 07:22:13 +00:00
}
2008-03-26 10:38:31 +00:00
2008-12-22 18:40:57 +00:00
CompanyID NetworkLobbyFindCompanyIndex ( byte pos )
{
/* Scroll through all this->company_info and get the 'pos' item that is not empty */
for ( CompanyID i = COMPANY_FIRST ; i < MAX_COMPANIES ; i + + ) {
if ( ! StrEmpty ( this - > company_info [ i ] . company_name ) ) {
if ( pos - - = = 0 ) return i ;
}
}
return COMPANY_FIRST ;
}
2008-05-11 07:22:13 +00:00
virtual void OnPaint ( )
{
const NetworkGameInfo * gi = & this - > server - > info ;
int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY , pos ;
2009-01-12 17:11:45 +00:00
/* Join button is disabled when no company is selected and for AI companies*/
this - > SetWidgetDisabledState ( NLWW_JOIN , this - > company = = INVALID_COMPANY | | GetLobbyCompanyInfo ( this - > company ) - > ai ) ;
2008-05-11 07:22:13 +00:00
/* Cannot start new company if there are too many */
this - > SetWidgetDisabledState ( NLWW_NEW , gi - > companies_on > = gi - > companies_max ) ;
/* Cannot spectate if there are too many spectators */
this - > SetWidgetDisabledState ( NLWW_SPECTATE , gi - > spectators_on > = gi - > spectators_max ) ;
/* Draw window widgets */
SetDParamStr ( 0 , gi - > server_name ) ;
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-05-11 07:22:13 +00:00
2008-12-24 09:53:15 +00:00
SetVScrollCount ( this , gi - > companies_on ) ;
2008-05-11 07:22:13 +00:00
/* Draw company list */
pos = this - > vscroll . pos ;
while ( pos < gi - > companies_on ) {
byte company = NetworkLobbyFindCompanyIndex ( pos ) ;
bool income = false ;
if ( this - > company = = company ) {
GfxFillRect ( 11 , y - 1 , 154 , y + 10 , 10 ) ; // show highlighted item with a different colour
2008-03-26 10:38:31 +00:00
}
2004-12-20 16:02:01 +00:00
2009-03-21 20:12:12 +00:00
DrawString ( 13 , 135 , y , this - > company_info [ company ] . company_name , TC_BLACK ) ;
2008-12-22 18:40:57 +00:00
if ( this - > company_info [ company ] . use_password ! = 0 ) DrawSprite ( SPR_LOCK , PAL_NONE , 135 , y ) ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
/* If the company's income was positive puts a green dot else a red dot */
2008-12-22 18:40:57 +00:00
if ( this - > company_info [ company ] . income > = 0 ) income = true ;
2008-05-11 07:22:13 +00:00
DrawSprite ( SPR_BLOT , income ? PALETTE_TO_GREEN : PALETTE_TO_RED , 145 , y ) ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
pos + + ;
y + = NET_PRC__SIZE_OF_ROW ;
2008-12-24 09:53:15 +00:00
if ( pos > = this - > vscroll . pos + this - > vscroll . cap ) break ;
2008-05-11 07:22:13 +00:00
}
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
/* Draw info about selected company when it is selected in the left window */
GfxFillRect ( 174 , 39 , 403 , 75 , 157 ) ;
2009-03-21 22:00:00 +00:00
DrawString ( this - > widget [ NLWW_DETAILS ] . left + 10 , this - > widget [ NLWW_DETAILS ] . right - 10 , 50 , STR_NETWORK_COMPANY_INFO , TC_FROMSTRING , SA_CENTER ) ;
2008-12-22 18:40:57 +00:00
if ( this - > company ! = INVALID_COMPANY & & ! StrEmpty ( this - > company_info [ this - > company ] . company_name ) ) {
2009-03-21 22:00:00 +00:00
const uint x = this - > widget [ NLWW_DETAILS ] . left + 10 ;
2008-05-11 07:22:13 +00:00
y = 80 ;
SetDParam ( 0 , gi - > clients_on ) ;
SetDParam ( 1 , gi - > clients_max ) ;
SetDParam ( 2 , gi - > companies_on ) ;
SetDParam ( 3 , gi - > companies_max ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_CLIENTS ) ;
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParamStr ( 0 , this - > company_info [ this - > company ] . company_name ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_COMPANY_NAME ) ;
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . inaugurated_year ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_INAUGURATION_YEAR ) ; // inauguration year
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . company_value ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_VALUE ) ; // company value
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . money ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_CURRENT_BALANCE ) ; // current balance
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . income ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_LAST_YEARS_INCOME ) ; // last year's income
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . performance ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_PERFORMANCE ) ; // performance
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . num_vehicle [ 0 ] ) ;
SetDParam ( 1 , this - > company_info [ this - > company ] . num_vehicle [ 1 ] ) ;
SetDParam ( 2 , this - > company_info [ this - > company ] . num_vehicle [ 2 ] ) ;
SetDParam ( 3 , this - > company_info [ this - > company ] . num_vehicle [ 3 ] ) ;
SetDParam ( 4 , this - > company_info [ this - > company ] . num_vehicle [ 4 ] ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_VEHICLES ) ; // vehicles
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParam ( 0 , this - > company_info [ this - > company ] . num_station [ 0 ] ) ;
SetDParam ( 1 , this - > company_info [ this - > company ] . num_station [ 1 ] ) ;
SetDParam ( 2 , this - > company_info [ this - > company ] . num_station [ 2 ] ) ;
SetDParam ( 3 , this - > company_info [ this - > company ] . num_station [ 3 ] ) ;
SetDParam ( 4 , this - > company_info [ this - > company ] . num_station [ 4 ] ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_STATIONS ) ; // stations
2008-05-11 07:22:13 +00:00
y + = 10 ;
2008-12-22 18:40:57 +00:00
SetDParamStr ( 0 , this - > company_info [ this - > company ] . clients ) ;
2009-04-26 15:26:19 +00:00
DrawString ( x , this - > widget [ NLWW_DETAILS ] . right , y , STR_NETWORK_PLAYERS ) ; // players
2008-05-11 07:22:13 +00:00
}
}
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
virtual void OnClick ( Point pt , int widget )
{
switch ( widget ) {
case NLWW_CLOSE : // Close 'X'
case NLWW_CANCEL : // Cancel button
ShowNetworkGameWindow ( ) ;
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
case NLWW_MATRIX : { // Company list
uint32 id_v = ( pt . y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY ) / NET_PRC__SIZE_OF_ROW ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
if ( id_v > = this - > vscroll . cap ) break ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
id_v + = this - > vscroll . pos ;
2008-09-30 20:39:50 +00:00
this - > company = ( id_v > = this - > server - > info . companies_on ) ? INVALID_COMPANY : NetworkLobbyFindCompanyIndex ( id_v ) ;
2008-05-11 07:22:13 +00:00
this - > SetDirty ( ) ;
} break ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
case NLWW_JOIN : // Join company
/* Button can be clicked only when it is enabled */
_network_playas = this - > company ;
2009-01-20 01:32:06 +00:00
NetworkClientConnectGame ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ;
2008-05-11 07:22:13 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
case NLWW_NEW : // New company
2008-09-30 20:39:50 +00:00
_network_playas = COMPANY_NEW_COMPANY ;
2009-01-20 01:32:06 +00:00
NetworkClientConnectGame ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ;
2008-05-11 07:22:13 +00:00
break ;
2008-03-26 10:38:31 +00:00
2008-05-11 07:22:13 +00:00
case NLWW_SPECTATE : // Spectate game
2008-09-30 20:39:50 +00:00
_network_playas = COMPANY_SPECTATOR ;
2009-01-20 01:32:06 +00:00
NetworkClientConnectGame ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ;
2008-05-11 07:22:13 +00:00
break ;
2006-01-26 12:56:05 +00:00
2008-05-11 07:22:13 +00:00
case NLWW_REFRESH : // Refresh
2009-01-20 01:32:06 +00:00
NetworkTCPQueryServer ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ; // company info
NetworkUDPQueryServer ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ; // general data
2008-12-22 18:40:57 +00:00
/* Clear the information so removed companies don't remain */
2009-02-24 22:25:23 +00:00
memset ( this - > company_info , 0 , sizeof ( this - > company_info ) ) ;
2008-05-11 07:22:13 +00:00
break ;
}
2004-08-09 17:04:08 +00:00
}
2008-08-31 20:54:01 +00:00
virtual void OnDoubleClick ( Point pt , int widget )
{
if ( widget = = NLWW_MATRIX ) {
/* is the Join button enabled? */
if ( ! this - > IsWidgetDisabled ( NLWW_JOIN ) ) this - > OnClick ( pt , NLWW_JOIN ) ;
}
}
2008-05-11 07:22:13 +00:00
} ;
2004-08-09 17:04:08 +00:00
static const Widget _network_lobby_window_widgets [ ] = {
2009-04-21 23:40:56 +00:00
{ WWT_CLOSEBOX , RESIZE_NONE , COLOUR_LIGHT_BLUE , 0 , 10 , 0 , 13 , STR_BLACK_CROSS , STR_TOOLTIP_CLOSE_WINDOW } , // NLWW_CLOSE
2009-05-05 20:36:16 +00:00
{ WWT_CAPTION , RESIZE_NONE , COLOUR_LIGHT_BLUE , 11 , 419 , 0 , 13 , STR_NETWORK_GAME_LOBBY , STR_NULL } , // NLWW_CAPTION
{ WWT_PANEL , RESIZE_NONE , COLOUR_LIGHT_BLUE , 0 , 419 , 14 , 234 , 0x0 , STR_NULL } , // NLWW_BACKGROUND
{ WWT_TEXT , RESIZE_NONE , COLOUR_LIGHT_BLUE , 10 , 419 , 22 , 34 , STR_NETWORK_PREPARE_TO_JOIN , STR_NULL } , // NLWW_TEXT
2007-11-25 11:36:45 +00:00
/* company list */
2009-05-05 20:36:16 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_WHITE , 10 , 155 , 38 , 49 , 0x0 , STR_NULL } , // NLWW_HEADER
2008-08-03 02:18:45 +00:00
{ WWT_MATRIX , RESIZE_NONE , COLOUR_LIGHT_BLUE , 10 , 155 , 50 , 190 , ( 10 < < 8 ) + 1 , STR_NETWORK_COMPANY_LIST_TIP } , // NLWW_MATRIX
2009-05-05 20:36:16 +00:00
{ WWT_SCROLLBAR , RESIZE_NONE , COLOUR_LIGHT_BLUE , 156 , 167 , 38 , 190 , 0x0 , STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST } , // NLWW_SCROLLBAR
2007-11-25 11:36:45 +00:00
2008-09-30 20:39:50 +00:00
/* company info */
2008-08-03 02:18:45 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_LIGHT_BLUE , 173 , 404 , 38 , 190 , 0x0 , STR_NULL } , // NLWW_DETAILS
2007-11-25 11:36:45 +00:00
/* buttons */
2008-08-03 02:18:45 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 10 , 151 , 200 , 211 , STR_NETWORK_JOIN_COMPANY , STR_NETWORK_JOIN_COMPANY_TIP } , // NLWW_JOIN
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 10 , 151 , 215 , 226 , STR_NETWORK_NEW_COMPANY , STR_NETWORK_NEW_COMPANY_TIP } , // NLWW_NEW
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 158 , 268 , 200 , 211 , STR_NETWORK_SPECTATE_GAME , STR_NETWORK_SPECTATE_GAME_TIP } , // NLWW_SPECTATE
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 158 , 268 , 215 , 226 , STR_NETWORK_REFRESH , STR_NETWORK_REFRESH_TIP } , // NLWW_REFRESH
2009-04-21 23:40:56 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 278 , 388 , 200 , 211 , STR_QUERY_CANCEL , STR_NULL } , // NLWW_CANCEL
2004-08-09 17:04:08 +00:00
2004-09-07 21:48:09 +00:00
{ WIDGETS_END } ,
2004-08-09 17:04:08 +00:00
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_network_lobby_window_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_LIGHT_BLUE , NLWW_CLOSE ) ,
NWidget ( WWT_CAPTION , COLOUR_LIGHT_BLUE , NLWW_CAPTION ) , SetDataTip ( STR_NETWORK_GAME_LOBBY , STR_NULL ) ,
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NLWW_BACKGROUND ) ,
NWidget ( WWT_TEXT , COLOUR_LIGHT_BLUE , NLWW_TEXT ) , SetDataTip ( STR_NETWORK_PREPARE_TO_JOIN , STR_NULL ) , SetMinimalSize ( 410 , 13 ) , SetPadding ( 8 , 0 , 0 , 10 ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 3 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 10 , 0 , 15 ) ,
/* Company list. */
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_PANEL , COLOUR_WHITE , NLWW_HEADER ) , SetMinimalSize ( 146 , 12 ) , SetFill ( false , false ) , EndContainer ( ) ,
NWidget ( WWT_MATRIX , COLOUR_LIGHT_BLUE , NLWW_MATRIX ) , SetMinimalSize ( 146 , 141 ) , SetDataTip ( ( 10 < < 8 ) + 1 , STR_NETWORK_COMPANY_LIST_TIP ) ,
EndContainer ( ) ,
NWidget ( WWT_SCROLLBAR , COLOUR_LIGHT_BLUE , NLWW_SCROLLBAR ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 5 , 0 ) ,
/* Company info. */
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE , NLWW_DETAILS ) , SetMinimalSize ( 232 , 153 ) , SetFill ( false , false ) , EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 9 ) ,
/* Buttons. */
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 10 , 0 , 31 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NLWW_JOIN ) , SetMinimalSize ( 142 , 12 ) , SetDataTip ( STR_NETWORK_JOIN_COMPANY , STR_NETWORK_JOIN_COMPANY_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 3 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NLWW_NEW ) , SetMinimalSize ( 142 , 12 ) , SetDataTip ( STR_NETWORK_NEW_COMPANY , STR_NETWORK_NEW_COMPANY_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , SetPadding ( 0 , 0 , 0 , 6 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NLWW_SPECTATE ) , SetMinimalSize ( 111 , 12 ) , SetDataTip ( STR_NETWORK_SPECTATE_GAME , STR_NETWORK_SPECTATE_GAME_TIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 3 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NLWW_REFRESH ) , SetMinimalSize ( 111 , 12 ) , SetDataTip ( STR_NETWORK_REFRESH , STR_NETWORK_REFRESH_TIP ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , SetPadding ( 0 , 0 , 0 , 9 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NLWW_CANCEL ) , SetMinimalSize ( 111 , 12 ) , SetDataTip ( STR_QUERY_CANCEL , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 15 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 8 ) ,
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _network_lobby_window_desc (
2007-07-27 12:49:04 +00:00
WDP_CENTER , WDP_CENTER , 420 , 235 , 420 , 235 ,
2007-02-01 15:49:12 +00:00
WC_NETWORK_WINDOW , WC_NONE ,
2004-08-09 17:04:08 +00:00
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS ,
2009-05-05 20:40:08 +00:00
_network_lobby_window_widgets , _nested_network_lobby_window_widgets , lengthof ( _nested_network_lobby_window_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2006-01-26 17:10:11 +00:00
/* Show the networklobbywindow with the selected server
* @ param ngl Selected game pointer which is passed to the new window */
2006-01-26 16:19:24 +00:00
static void ShowNetworkLobbyWindow ( NetworkGameList * ngl )
2004-08-09 17:04:08 +00:00
{
DeleteWindowById ( WC_NETWORK_WINDOW , 0 ) ;
2004-09-10 19:02:27 +00:00
2009-01-20 01:32:06 +00:00
NetworkTCPQueryServer ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ; // company info
NetworkUDPQueryServer ( NetworkAddress ( _settings_client . network . last_host , _settings_client . network . last_port ) ) ; // general data
2004-12-04 17:54:56 +00:00
2008-05-11 07:22:13 +00:00
new NetworkLobbyWindow ( & _network_lobby_window_desc , ngl ) ;
2004-12-04 17:54:56 +00:00
}
2004-08-09 17:04:08 +00:00
2008-12-22 18:40:57 +00:00
/**
* Get the company information of a given company to fill for the lobby .
* @ param company the company to get the company info struct from .
* @ return the company info struct to write the ( downloaded ) data to .
*/
NetworkCompanyInfo * GetLobbyCompanyInfo ( CompanyID company )
{
NetworkLobbyWindow * lobby = dynamic_cast < NetworkLobbyWindow * > ( FindWindowById ( WC_NETWORK_WINDOW , 0 ) ) ;
return ( lobby ! = NULL & & company < MAX_COMPANIES ) ? & lobby - > company_info [ company ] : NULL ;
}
2009-03-15 00:32:18 +00:00
/* The window below gives information about the connected clients
* and also makes able to give money to them , kick them ( if server )
* and stuff like that . */
2004-12-04 17:54:56 +00:00
2008-09-30 20:39:50 +00:00
extern void DrawCompanyIcon ( CompanyID cid , int x , int y ) ;
2004-12-04 17:54:56 +00:00
2009-03-15 00:32:18 +00:00
/* Every action must be of this form */
2004-12-04 17:54:56 +00:00
typedef void ClientList_Action_Proc ( byte client_no ) ;
2009-03-15 00:32:18 +00:00
/* Max 10 actions per client */
2004-12-04 17:54:56 +00:00
# define MAX_CLIENTLIST_ACTION 10
enum {
CLNWND_OFFSET = 16 ,
CLNWND_ROWSIZE = 10
} ;
2009-05-05 20:36:16 +00:00
/** Widget numbers of the client list window. */
enum ClientListWidgets {
CLW_CLOSE ,
CLW_CAPTION ,
CLW_STICKY ,
CLW_PANEL ,
} ;
2005-01-03 19:45:18 +00:00
static const Widget _client_list_widgets [ ] = {
2009-04-21 23:40:56 +00:00
{ WWT_CLOSEBOX , RESIZE_NONE , COLOUR_GREY , 0 , 10 , 0 , 13 , STR_BLACK_CROSS , STR_TOOLTIP_CLOSE_WINDOW } ,
{ WWT_CAPTION , RESIZE_NONE , COLOUR_GREY , 11 , 237 , 0 , 13 , STR_NETWORK_CLIENT_LIST , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS } ,
2008-08-03 02:18:45 +00:00
{ WWT_STICKYBOX , RESIZE_NONE , COLOUR_GREY , 238 , 249 , 0 , 13 , STR_NULL , STR_STICKY_BUTTON } ,
2004-12-04 17:54:56 +00:00
2008-08-03 02:18:45 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_GREY , 0 , 249 , 14 , 14 + CLNWND_ROWSIZE + 1 , 0x0 , STR_NULL } ,
2004-12-04 17:54:56 +00:00
{ WIDGETS_END } ,
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_client_list_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_GREY , CLW_CLOSE ) ,
NWidget ( WWT_CAPTION , COLOUR_GREY , CLW_CAPTION ) , SetDataTip ( STR_NETWORK_CLIENT_LIST , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
NWidget ( WWT_STICKYBOX , COLOUR_GREY , CLW_STICKY ) ,
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , CLW_PANEL ) , SetMinimalSize ( 250 , CLNWND_ROWSIZE + 2 ) , EndContainer ( ) ,
} ;
2005-01-03 19:45:18 +00:00
static const Widget _client_list_popup_widgets [ ] = {
2008-08-03 02:18:45 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_GREY , 0 , 99 , 0 , 0 , 0 , STR_NULL } ,
2004-12-04 17:54:56 +00:00
{ WIDGETS_END } ,
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_client_list_popup_widgets [ ] = {
NWidget ( WWT_PANEL , COLOUR_GREY , 0 ) , SetMinimalSize ( 100 , 1 ) , EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _client_list_desc (
2007-07-27 12:49:04 +00:00
WDP_AUTO , WDP_AUTO , 250 , 1 , 250 , 1 ,
2007-02-01 15:49:12 +00:00
WC_CLIENT_LIST , WC_NONE ,
2007-06-23 14:13:05 +00:00
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON ,
2009-05-05 20:40:08 +00:00
_client_list_widgets , _nested_client_list_widgets , lengthof ( _client_list_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-12-04 17:54:56 +00:00
2009-03-15 00:32:18 +00:00
/* Finds the Xth client-info that is active */
2009-04-04 00:48:48 +00:00
static NetworkClientInfo * NetworkFindClientInfo ( byte client_no )
2004-12-04 17:54:56 +00:00
{
2009-04-04 00:48:48 +00:00
NetworkClientInfo * ci ;
2005-11-13 13:43:55 +00:00
2008-12-23 08:39:30 +00:00
FOR_ALL_CLIENT_INFOS ( ci ) {
2004-12-04 17:54:56 +00:00
if ( client_no = = 0 ) return ci ;
client_no - - ;
}
return NULL ;
2004-08-09 17:04:08 +00:00
}
2004-12-04 17:54:56 +00:00
2009-03-15 00:32:18 +00:00
/* Here we start to define the options out of the menu */
2004-12-04 17:54:56 +00:00
static void ClientList_Kick ( byte client_no )
{
2009-03-06 12:42:01 +00:00
const NetworkClientInfo * ci = NetworkFindClientInfo ( client_no ) ;
if ( ci = = NULL ) return ;
NetworkServerKickClient ( ci - > client_id ) ;
2004-12-04 17:54:56 +00:00
}
2005-01-02 12:03:43 +00:00
static void ClientList_Ban ( byte client_no )
2004-12-04 17:54:56 +00:00
{
2009-04-04 00:48:48 +00:00
NetworkClientInfo * ci = NetworkFindClientInfo ( client_no ) ;
2005-01-02 12:03:43 +00:00
2009-03-06 12:42:01 +00:00
if ( ci = = NULL ) return ;
2005-01-02 12:03:43 +00:00
2009-03-06 12:42:01 +00:00
NetworkServerBanIP ( GetClientIP ( ci ) ) ;
2005-01-02 12:03:43 +00:00
}
2004-12-04 17:54:56 +00:00
static void ClientList_GiveMoney ( byte client_no )
{
2008-03-26 10:38:31 +00:00
if ( NetworkFindClientInfo ( client_no ) ! = NULL ) {
2006-10-17 22:16:46 +00:00
ShowNetworkGiveMoneyWindow ( NetworkFindClientInfo ( client_no ) - > client_playas ) ;
2008-03-26 10:38:31 +00:00
}
2004-12-04 17:54:56 +00:00
}
static void ClientList_SpeakToClient ( byte client_no )
{
2008-03-26 10:38:31 +00:00
if ( NetworkFindClientInfo ( client_no ) ! = NULL ) {
2008-12-22 12:59:31 +00:00
ShowNetworkChatQueryWindow ( DESTTYPE_CLIENT , NetworkFindClientInfo ( client_no ) - > client_id ) ;
2008-03-26 10:38:31 +00:00
}
2004-12-04 17:54:56 +00:00
}
2006-10-21 22:29:14 +00:00
static void ClientList_SpeakToCompany ( byte client_no )
2004-12-04 17:54:56 +00:00
{
2008-03-26 10:38:31 +00:00
if ( NetworkFindClientInfo ( client_no ) ! = NULL ) {
2006-10-21 22:29:14 +00:00
ShowNetworkChatQueryWindow ( DESTTYPE_TEAM , NetworkFindClientInfo ( client_no ) - > client_playas ) ;
2008-03-26 10:38:31 +00:00
}
2004-12-04 17:54:56 +00:00
}
static void ClientList_SpeakToAll ( byte client_no )
{
ShowNetworkChatQueryWindow ( DESTTYPE_BROADCAST , 0 ) ;
}
static void ClientList_None ( byte client_no )
{
2008-03-26 10:38:31 +00:00
/* No action ;) */
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
struct NetworkClientListPopupWindow : Window {
int sel_index ;
int client_no ;
char action [ MAX_CLIENTLIST_ACTION ] [ 50 ] ;
ClientList_Action_Proc * proc [ MAX_CLIENTLIST_ACTION ] ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
NetworkClientListPopupWindow ( int x , int y , const Widget * widgets , int client_no ) :
2008-05-18 20:40:30 +00:00
Window ( x , y , 150 , 100 , WC_TOOLBAR_MENU , widgets ) ,
2008-05-15 20:04:10 +00:00
sel_index ( 0 ) , client_no ( client_no )
{
/*
* Fill the actions this client has .
* Watch is , max 50 chars long !
*/
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
const NetworkClientInfo * ci = NetworkFindClientInfo ( client_no ) ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
int i = 0 ;
2008-12-22 12:59:31 +00:00
if ( _network_own_client_id ! = ci - > client_id ) {
2008-05-15 20:04:10 +00:00
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_SpeakToClient ;
}
2004-12-04 17:54:56 +00:00
2008-09-30 20:39:50 +00:00
if ( IsValidCompanyID ( ci - > client_playas ) | | ci - > client_playas = = COMPANY_SPECTATOR ) {
2008-05-15 20:04:10 +00:00
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_SpeakToCompany ;
}
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_SpeakToAll ;
2008-12-22 12:59:31 +00:00
if ( _network_own_client_id ! = ci - > client_id ) {
2008-09-30 20:39:50 +00:00
/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed */
if ( IsValidCompanyID ( _network_playas ) & & IsValidCompanyID ( ci - > client_playas ) & & _settings_game . economy . give_money ) {
2008-05-15 20:04:10 +00:00
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_GIVE_MONEY , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_GiveMoney ;
}
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* A server can kick clients (but not himself) */
2008-12-22 12:59:31 +00:00
if ( _network_server & & _network_own_client_id ! = ci - > client_id ) {
2008-05-15 20:04:10 +00:00
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_KICK , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_Kick ;
2004-12-04 17:54:56 +00:00
2008-10-28 16:04:41 +00:00
seprintf ( this - > action [ i ] , lastof ( this - > action [ i ] ) , " Ban " ) ; // XXX GetString?
2008-05-15 20:04:10 +00:00
this - > proc [ i + + ] = & ClientList_Ban ;
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
if ( i = = 0 ) {
GetString ( this - > action [ i ] , STR_NETWORK_CLIENTLIST_NONE , lastof ( this - > action [ i ] ) ) ;
this - > proc [ i + + ] = & ClientList_None ;
}
2005-01-03 19:45:18 +00:00
2008-05-15 20:04:10 +00:00
/* Calculate the height */
int h = ClientListPopupHeight ( ) ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* Allocate the popup */
this - > widget [ 0 ] . bottom = this - > widget [ 0 ] . top + h ;
this - > widget [ 0 ] . right = this - > widget [ 0 ] . left + 150 ;
this - > flags4 & = ~ WF_WHITE_BORDER_MASK ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
this - > FindWindowPlacementAndResize ( 150 , h + 1 ) ;
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
/**
* An action is clicked ! What do we do ?
2008-03-26 10:38:31 +00:00
*/
2008-05-15 20:04:10 +00:00
void HandleClientListPopupClick ( byte index )
{
/* A click on the Popup of the ClientList.. handle the command */
if ( index < MAX_CLIENTLIST_ACTION & & this - > proc [ index ] ! = NULL ) {
this - > proc [ index ] ( this - > client_no ) ;
}
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
/**
* Finds the amount of actions in the popup and set the height correct
*/
uint ClientListPopupHeight ( )
{
int num = 0 ;
2009-03-15 00:32:18 +00:00
/* Find the amount of actions */
2008-05-15 20:04:10 +00:00
for ( int i = 0 ; i < MAX_CLIENTLIST_ACTION ; i + + ) {
if ( this - > action [ i ] [ 0 ] = = ' \0 ' ) continue ;
if ( this - > proc [ i ] = = NULL ) continue ;
num + + ;
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
num * = CLNWND_ROWSIZE ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
return num + 1 ;
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
virtual void OnPaint ( )
{
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* Draw the actions */
int sel = this - > sel_index ;
int y = 1 ;
for ( int i = 0 ; i < MAX_CLIENTLIST_ACTION ; i + + , y + = CLNWND_ROWSIZE ) {
if ( this - > action [ i ] [ 0 ] = = ' \0 ' ) continue ;
if ( this - > proc [ i ] = = NULL ) continue ;
TextColour colour ;
if ( sel - - = = 0 ) { // Selected item, highlight it
GfxFillRect ( 1 , y , 150 - 2 , y + CLNWND_ROWSIZE - 1 , 0 ) ;
colour = TC_WHITE ;
} else {
colour = TC_BLACK ;
}
2005-01-03 19:45:18 +00:00
2009-03-21 22:46:17 +00:00
DrawString ( 4 , this - > width - 4 , y , this - > action [ i ] , colour ) ;
2008-05-15 20:04:10 +00:00
}
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
virtual void OnMouseLoop ( )
{
/* We selected an action */
int index = ( _cursor . pos . y - this - > top ) / CLNWND_ROWSIZE ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
if ( _left_button_down ) {
if ( index = = - 1 | | index = = this - > sel_index ) return ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
this - > sel_index = index ;
this - > SetDirty ( ) ;
} else {
if ( index > = 0 & & _cursor . pos . y > = this - > top ) {
HandleClientListPopupClick ( index ) ;
2008-03-26 10:38:31 +00:00
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
DeleteWindowById ( WC_TOOLBAR_MENU , 0 ) ;
}
}
} ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/**
* Show the popup ( action list )
*/
static void PopupClientList ( int client_no , int x , int y )
{
2009-05-05 20:40:08 +00:00
static Widget * generated_client_list_popup_widgets = NULL ;
2008-05-15 20:04:10 +00:00
DeleteWindowById ( WC_TOOLBAR_MENU , 0 ) ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
if ( NetworkFindClientInfo ( client_no ) = = NULL ) return ;
2004-12-04 17:54:56 +00:00
2009-05-05 20:40:08 +00:00
const Widget * wid = InitializeWidgetArrayFromNestedWidgets ( _nested_client_list_widgets , lengthof ( _nested_client_list_widgets ) ,
_client_list_widgets , & generated_client_list_popup_widgets ) ;
new NetworkClientListPopupWindow ( x , y , wid , client_no ) ;
2004-12-04 17:54:56 +00:00
}
2008-03-26 10:38:31 +00:00
/**
* Main handle for clientlist
*/
2008-05-15 20:04:10 +00:00
struct NetworkClientListWindow : Window
2004-12-04 17:54:56 +00:00
{
2008-12-23 17:12:20 +00:00
int selected_item ;
int selected_y ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
NetworkClientListWindow ( const WindowDesc * desc , WindowNumber window_number ) :
Window ( desc , window_number ) ,
2008-12-23 17:12:20 +00:00
selected_item ( - 1 ) ,
selected_y ( 0 )
2008-05-15 20:04:10 +00:00
{
this - > FindWindowPlacementAndResize ( desc ) ;
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/**
* Finds the amount of clients and set the height correct
*/
bool CheckClientListHeight ( )
{
int num = 0 ;
const NetworkClientInfo * ci ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* Should be replaced with a loop through all clients */
2008-12-23 08:39:30 +00:00
FOR_ALL_CLIENT_INFOS ( ci ) {
2008-12-23 17:12:20 +00:00
if ( ci - > client_playas ! = COMPANY_INACTIVE_CLIENT ) num + + ;
2008-05-15 20:04:10 +00:00
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
num * = CLNWND_ROWSIZE ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* If height is changed */
if ( this - > height ! = CLNWND_OFFSET + num + 1 ) {
2009-03-15 00:32:18 +00:00
/* XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1) */
2008-05-15 20:04:10 +00:00
this - > SetDirty ( ) ;
this - > widget [ 3 ] . bottom = this - > widget [ 3 ] . top + num + 2 ;
this - > height = CLNWND_OFFSET + num + 1 ;
this - > SetDirty ( ) ;
return false ;
}
return true ;
}
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
virtual void OnPaint ( )
{
NetworkClientInfo * ci ;
int i = 0 ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
/* Check if we need to reset the height */
if ( ! this - > CheckClientListHeight ( ) ) return ;
2004-12-04 17:54:56 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2004-12-04 17:54:56 +00:00
2008-05-15 20:04:10 +00:00
int y = CLNWND_OFFSET ;
2004-12-04 17:54:56 +00:00
2008-12-23 08:39:30 +00:00
FOR_ALL_CLIENT_INFOS ( ci ) {
2008-05-15 20:04:10 +00:00
TextColour colour ;
if ( this - > selected_item = = i + + ) { // Selected item, highlight it
GfxFillRect ( 1 , y , 248 , y + CLNWND_ROWSIZE - 1 , 0 ) ;
colour = TC_WHITE ;
} else {
colour = TC_BLACK ;
2008-03-26 10:38:31 +00:00
}
2004-12-04 17:54:56 +00:00
2008-12-22 12:59:31 +00:00
if ( ci - > client_id = = CLIENT_ID_SERVER ) {
2009-03-22 14:39:20 +00:00
DrawString ( 4 , 81 , y , STR_NETWORK_SERVER , colour ) ;
2008-03-26 10:38:31 +00:00
} else {
2009-03-22 14:39:20 +00:00
DrawString ( 4 , 81 , y , STR_NETWORK_CLIENT , colour ) ;
2008-03-26 10:38:31 +00:00
}
2008-05-15 20:04:10 +00:00
/* Filter out spectators */
2008-09-30 20:39:50 +00:00
if ( IsValidCompanyID ( ci - > client_playas ) ) DrawCompanyIcon ( ci - > client_playas , 64 , y + 1 ) ;
2004-12-04 17:54:56 +00:00
2009-03-21 22:46:17 +00:00
DrawString ( 81 , this - > width - 2 , y , ci - > client_name , colour ) ;
2008-05-15 20:04:10 +00:00
y + = CLNWND_ROWSIZE ;
}
2004-12-04 17:54:56 +00:00
}
2008-05-15 20:04:10 +00:00
virtual void OnClick ( Point pt , int widget )
{
/* Show the popup with option */
2008-12-23 17:12:20 +00:00
if ( this - > selected_item ! = - 1 ) {
2008-05-15 20:04:10 +00:00
PopupClientList ( this - > selected_item , pt . x + this - > left , pt . y + this - > top ) ;
}
}
virtual void OnMouseOver ( Point pt , int widget )
{
/* -1 means we left the current window */
if ( pt . y = = - 1 ) {
this - > selected_y = 0 ;
2008-12-23 17:12:20 +00:00
this - > selected_item = - 1 ;
2008-05-15 20:04:10 +00:00
this - > SetDirty ( ) ;
return ;
}
/* It did not change.. no update! */
if ( pt . y = = this - > selected_y ) return ;
/* Find the new selected item (if any) */
this - > selected_y = pt . y ;
if ( pt . y > CLNWND_OFFSET ) {
this - > selected_item = ( pt . y - CLNWND_OFFSET ) / CLNWND_ROWSIZE ;
} else {
2008-12-23 17:12:20 +00:00
this - > selected_item = - 1 ;
2008-05-15 20:04:10 +00:00
}
/* Repaint */
this - > SetDirty ( ) ;
}
} ;
2004-12-04 17:54:56 +00:00
2007-03-07 11:47:46 +00:00
void ShowClientList ( )
2004-12-04 17:54:56 +00:00
{
2008-05-15 20:04:10 +00:00
AllocateWindowDescFront < NetworkClientListWindow > ( & _client_list_desc , 0 ) ;
2004-12-04 17:54:56 +00:00
}
2006-09-01 13:35:43 +00:00
static NetworkPasswordType pw_type ;
void ShowNetworkNeedPassword ( NetworkPasswordType npt )
{
StringID caption ;
pw_type = npt ;
switch ( npt ) {
default : NOT_REACHED ( ) ;
2006-10-08 11:54:47 +00:00
case NETWORK_GAME_PASSWORD : caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION ; break ;
case NETWORK_COMPANY_PASSWORD : caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION ; break ;
2006-09-01 13:35:43 +00:00
}
2008-09-15 16:29:40 +00:00
ShowQueryString ( STR_EMPTY , caption , 20 , 180 , FindWindowById ( WC_NETWORK_STATUS_WINDOW , 0 ) , CS_ALPHANUMERAL , QSF_NONE ) ;
2006-09-01 13:35:43 +00:00
}
2009-03-15 00:32:18 +00:00
/* Vars needed for the join-GUI */
2008-05-30 18:20:26 +00:00
NetworkJoinStatus _network_join_status ;
uint8 _network_join_waiting ;
2009-01-16 12:59:47 +00:00
uint32 _network_join_bytes ;
uint32 _network_join_bytes_total ;
2008-05-30 18:20:26 +00:00
2009-03-21 21:26:10 +00:00
/** Widgets used for the join status window. */
enum NetworkJoinStatusWidgets {
NJSW_CAPTION , ///< Caption of the window
NJSW_BACKGROUND , ///< Background
NJSW_CANCELOK , ///< Cancel/OK button
} ;
2008-05-17 08:00:13 +00:00
struct NetworkJoinStatusWindow : Window {
NetworkJoinStatusWindow ( const WindowDesc * desc ) : Window ( desc )
{
this - > parent = FindWindowById ( WC_NETWORK_WINDOW , 0 ) ;
2009-01-20 11:21:06 +00:00
this - > FindWindowPlacementAndResize ( desc ) ;
2008-05-17 08:00:13 +00:00
}
2006-09-01 13:35:43 +00:00
2008-05-17 08:00:13 +00:00
virtual void OnPaint ( )
{
uint8 progress ; // used for progress bar
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2004-12-04 17:54:56 +00:00
2009-04-26 15:26:19 +00:00
DrawString ( this - > widget [ NJSW_BACKGROUND ] . left + 2 , this - > widget [ NJSW_BACKGROUND ] . right - 2 , 35 , STR_NETWORK_CONNECTING_1 + _network_join_status , TC_FROMSTRING , SA_CENTER ) ;
2008-05-17 08:00:13 +00:00
switch ( _network_join_status ) {
case NETWORK_JOIN_STATUS_CONNECTING : case NETWORK_JOIN_STATUS_AUTHORIZING :
case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO :
progress = 10 ; // first two stages 10%
break ;
case NETWORK_JOIN_STATUS_WAITING :
SetDParam ( 0 , _network_join_waiting ) ;
2009-04-26 15:26:19 +00:00
DrawString ( this - > widget [ NJSW_BACKGROUND ] . left + 2 , this - > widget [ NJSW_BACKGROUND ] . right - 2 , 46 , STR_NETWORK_CONNECTING_WAITING , TC_FROMSTRING , SA_CENTER ) ;
2008-05-17 08:00:13 +00:00
progress = 15 ; // third stage is 15%
break ;
case NETWORK_JOIN_STATUS_DOWNLOADING :
2009-01-16 12:59:47 +00:00
SetDParam ( 0 , _network_join_bytes ) ;
SetDParam ( 1 , _network_join_bytes_total ) ;
2009-04-26 15:26:19 +00:00
DrawString ( this - > widget [ NJSW_BACKGROUND ] . left + 2 , this - > widget [ NJSW_BACKGROUND ] . right - 2 , 46 , STR_NETWORK_CONNECTING_DOWNLOADING , TC_FROMSTRING , SA_CENTER ) ;
2008-05-17 08:00:13 +00:00
/* Fallthrough */
2009-03-15 00:32:18 +00:00
default : // Waiting is 15%, so the resting receivement of map is maximum 70%
2009-01-16 12:59:47 +00:00
progress = 15 + _network_join_bytes * ( 100 - 15 ) / _network_join_bytes_total ;
2008-05-17 08:00:13 +00:00
}
2004-12-04 17:54:56 +00:00
2008-05-17 08:00:13 +00:00
/* Draw nice progress bar :) */
2008-08-01 03:43:53 +00:00
DrawFrameRect ( 20 , 18 , ( int ) ( ( this - > width - 20 ) * progress / 100 ) , 28 , COLOUR_MAUVE , FR_NONE ) ;
2008-05-17 08:00:13 +00:00
}
2006-09-01 13:35:43 +00:00
2008-05-17 08:00:13 +00:00
virtual void OnClick ( Point pt , int widget )
{
2009-03-21 21:26:10 +00:00
if ( widget = = NJSW_CANCELOK ) { // Disconnect button
2008-05-17 08:00:13 +00:00
NetworkDisconnect ( ) ;
2009-02-25 00:45:52 +00:00
SwitchToMode ( SM_MENU ) ;
2008-05-17 08:00:13 +00:00
ShowNetworkGameWindow ( ) ;
}
2004-12-04 17:54:56 +00:00
}
2008-05-17 08:00:13 +00:00
virtual void OnQueryTextFinished ( char * str )
{
if ( StrEmpty ( str ) ) {
NetworkDisconnect ( ) ;
ShowNetworkGameWindow ( ) ;
} else {
SEND_COMMAND ( PACKET_CLIENT_PASSWORD ) ( pw_type , str ) ;
}
}
} ;
2004-12-04 17:54:56 +00:00
static const Widget _network_join_status_window_widget [ ] = {
2009-05-05 20:36:16 +00:00
{ WWT_CAPTION , RESIZE_NONE , COLOUR_GREY , 0 , 249 , 0 , 13 , STR_NETWORK_CONNECTING , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS } , // NJSW_CAPTION
2009-03-21 21:26:10 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_GREY , 0 , 249 , 14 , 84 , 0x0 , STR_NULL } , // NJSW_BACKGROUND
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_WHITE , 75 , 175 , 69 , 80 , STR_NETWORK_DISCONNECT , STR_NULL } , // NJSW_CANCELOK
2004-12-04 17:54:56 +00:00
{ WIDGETS_END } ,
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_network_join_status_window_widgets [ ] = {
NWidget ( WWT_CAPTION , COLOUR_GREY , NJSW_CAPTION ) , SetDataTip ( STR_NETWORK_CONNECTING , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , NJSW_BACKGROUND ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_WHITE , NJSW_CANCELOK ) , SetMinimalSize ( 101 , 12 ) , SetPadding ( 55 , 74 , 4 , 75 ) , SetDataTip ( STR_NETWORK_DISCONNECT , STR_NULL ) ,
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _network_join_status_window_desc (
2007-07-27 12:49:04 +00:00
WDP_CENTER , WDP_CENTER , 250 , 85 , 250 , 85 ,
2007-02-01 15:49:12 +00:00
WC_NETWORK_STATUS_WINDOW , WC_NONE ,
2006-12-30 01:52:09 +00:00
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL ,
2009-05-05 20:40:08 +00:00
_network_join_status_window_widget , _nested_network_join_status_window_widgets , lengthof ( _nested_network_join_status_window_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-12-04 17:54:56 +00:00
2007-03-07 11:47:46 +00:00
void ShowJoinStatusWindow ( )
2004-12-04 17:54:56 +00:00
{
DeleteWindowById ( WC_NETWORK_STATUS_WINDOW , 0 ) ;
2008-05-17 08:00:13 +00:00
new NetworkJoinStatusWindow ( & _network_join_status_window_desc ) ;
2004-12-15 21:13:52 +00:00
}
2004-12-04 17:54:56 +00:00
2004-12-14 16:53:38 +00:00
2007-12-02 14:48:26 +00:00
/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
enum NetworkCompanyPasswordWindowWidgets {
NCPWW_CLOSE , ///< Close 'X' button
NCPWW_CAPTION , ///< Caption of the whole window
NCPWW_BACKGROUND , ///< The background of the interface
NCPWW_LABEL , ///< Label in front of the password field
NCPWW_PASSWORD , ///< Input field for the password
NCPWW_SAVE_AS_DEFAULT_PASSWORD , ///< Toggle 'button' for saving the current password as default password
NCPWW_CANCEL , ///< Close the window without changing anything
NCPWW_OK , ///< Safe the password etc.
} ;
2008-05-11 12:26:20 +00:00
struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
2008-08-11 22:08:56 +00:00
NetworkCompanyPasswordWindow ( const WindowDesc * desc , Window * parent ) : QueryStringBaseWindow ( lengthof ( _settings_client . network . default_company_pass ) , desc )
2008-05-11 12:26:20 +00:00
{
2008-05-15 19:24:15 +00:00
this - > parent = parent ;
2008-05-11 12:26:20 +00:00
this - > afilter = CS_ALPHANUMERAL ;
2008-08-11 22:08:56 +00:00
InitializeTextBuffer ( & this - > text , this - > edit_str_buf , this - > edit_str_size , 0 ) ;
2009-02-09 01:22:29 +00:00
this - > SetFocusedWidget ( NCPWW_PASSWORD ) ;
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
this - > FindWindowPlacementAndResize ( desc ) ;
}
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
void OnOk ( )
{
if ( this - > IsWidgetLowered ( NCPWW_SAVE_AS_DEFAULT_PASSWORD ) ) {
2008-05-29 20:21:28 +00:00
snprintf ( _settings_client . network . default_company_pass , lengthof ( _settings_client . network . default_company_pass ) , " %s " , this - > edit_str_buf ) ;
2008-05-11 12:26:20 +00:00
}
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
/* empty password is a '*' because of console argument */
2008-08-11 22:08:56 +00:00
if ( StrEmpty ( this - > edit_str_buf ) ) snprintf ( this - > edit_str_buf , this - > edit_str_size , " * " ) ;
2008-05-11 12:26:20 +00:00
char * password = this - > edit_str_buf ;
NetworkChangeCompanyPassword ( 1 , & password ) ;
}
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnPaint ( )
{
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-05-11 12:26:20 +00:00
this - > DrawEditBox ( 4 ) ;
}
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
virtual void OnClick ( Point pt , int widget )
{
switch ( widget ) {
case NCPWW_OK :
this - > OnOk ( ) ;
2007-12-02 14:48:26 +00:00
2008-05-11 12:26:20 +00:00
/* FALL THROUGH */
case NCPWW_CANCEL :
delete this ;
break ;
2007-12-16 19:28:07 +00:00
2008-05-11 12:26:20 +00:00
case NCPWW_SAVE_AS_DEFAULT_PASSWORD :
this - > ToggleWidgetLoweredState ( NCPWW_SAVE_AS_DEFAULT_PASSWORD ) ;
this - > SetDirty ( ) ;
break ;
}
2007-12-02 14:48:26 +00:00
}
2008-05-11 12:26:20 +00:00
virtual void OnMouseLoop ( )
{
this - > HandleEditBox ( 4 ) ;
}
2008-05-17 23:11:06 +00:00
virtual EventState OnKeyPress ( uint16 key , uint16 keycode )
2008-05-11 12:26:20 +00:00
{
2009-03-11 09:21:11 +00:00
EventState state = ES_NOT_HANDLED ;
2008-05-17 23:11:06 +00:00
switch ( this - > HandleEditBoxKey ( 4 , key , keycode , state ) ) {
2008-10-25 19:59:11 +00:00
default : break ;
case HEBR_CONFIRM :
2008-05-11 12:26:20 +00:00
this - > OnOk ( ) ;
/* FALL THROUGH */
2008-10-25 19:59:11 +00:00
case HEBR_CANCEL :
2008-05-11 12:26:20 +00:00
delete this ;
break ;
}
2008-05-17 23:11:06 +00:00
return state ;
2008-05-11 12:26:20 +00:00
}
2009-01-03 13:59:05 +00:00
virtual void OnOpenOSKWindow ( int wid )
{
ShowOnScreenKeyboard ( this , wid , NCPWW_CANCEL , NCPWW_OK ) ;
}
2008-05-11 12:26:20 +00:00
} ;
2007-12-02 14:48:26 +00:00
static const Widget _ncp_window_widgets [ ] = {
2009-04-21 23:40:56 +00:00
{ WWT_CLOSEBOX , RESIZE_NONE , COLOUR_GREY , 0 , 10 , 0 , 13 , STR_BLACK_CROSS , STR_TOOLTIP_CLOSE_WINDOW } ,
{ WWT_CAPTION , RESIZE_NONE , COLOUR_GREY , 11 , 299 , 0 , 13 , STR_COMPANY_PASSWORD_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS } ,
2008-08-03 02:18:45 +00:00
{ WWT_PANEL , RESIZE_NONE , COLOUR_GREY , 0 , 299 , 14 , 50 , 0x0 , STR_NULL } ,
{ WWT_TEXT , RESIZE_NONE , COLOUR_GREY , 5 , 100 , 19 , 30 , STR_COMPANY_PASSWORD , STR_NULL } ,
{ WWT_EDITBOX , RESIZE_NONE , COLOUR_GREY , 101 , 294 , 19 , 30 , STR_SET_COMPANY_PASSWORD , STR_NULL } ,
{ WWT_TEXTBTN , RESIZE_NONE , COLOUR_GREY , 101 , 294 , 35 , 46 , STR_MAKE_DEFAULT_COMPANY_PASSWORD , STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP } ,
2009-04-21 23:40:56 +00:00
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_GREY , 0 , 149 , 51 , 62 , STR_QUERY_CANCEL , STR_COMPANY_PASSWORD_CANCEL } ,
{ WWT_PUSHTXTBTN , RESIZE_NONE , COLOUR_GREY , 150 , 299 , 51 , 62 , STR_QUERY_OK , STR_COMPANY_PASSWORD_OK } ,
2007-12-02 14:48:26 +00:00
{ WIDGETS_END } ,
} ;
2009-05-05 20:40:08 +00:00
static const NWidgetPart _nested_ncp_window_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_GREY , NCPWW_CLOSE ) ,
NWidget ( WWT_CAPTION , COLOUR_GREY , NCPWW_CAPTION ) , SetDataTip ( STR_COMPANY_PASSWORD_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , NCPWW_BACKGROUND ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 5 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 5 , 0 , 5 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , NCPWW_LABEL ) , SetMinimalSize ( 96 , 12 ) , SetDataTip ( STR_COMPANY_PASSWORD , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetFill ( false , true ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_EDITBOX , COLOUR_GREY , NCPWW_PASSWORD ) , SetMinimalSize ( 194 , 12 ) , SetDataTip ( STR_SET_COMPANY_PASSWORD , STR_NULL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 4 ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , NCPWW_SAVE_AS_DEFAULT_PASSWORD ) , SetMinimalSize ( 194 , 12 ) ,
SetDataTip ( STR_MAKE_DEFAULT_COMPANY_PASSWORD , STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 4 ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , NCPWW_CANCEL ) , SetMinimalSize ( 150 , 12 ) , SetDataTip ( STR_QUERY_CANCEL , STR_COMPANY_PASSWORD_CANCEL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , NCPWW_OK ) , SetMinimalSize ( 150 , 12 ) , SetDataTip ( STR_QUERY_OK , STR_COMPANY_PASSWORD_OK ) ,
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _ncp_window_desc (
2007-12-02 14:48:26 +00:00
WDP_AUTO , WDP_AUTO , 300 , 63 , 300 , 63 ,
WC_COMPANY_PASSWORD_WINDOW , WC_NONE ,
2007-12-06 15:58:39 +00:00
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON ,
2009-05-05 20:40:08 +00:00
_ncp_window_widgets , _nested_ncp_window_widgets , lengthof ( _nested_ncp_window_widgets )
2009-03-15 15:12:06 +00:00
) ;
2007-12-02 14:48:26 +00:00
2008-05-15 19:24:15 +00:00
void ShowNetworkCompanyPasswordWindow ( Window * parent )
2007-12-02 14:48:26 +00:00
{
DeleteWindowById ( WC_COMPANY_PASSWORD_WINDOW , 0 ) ;
2008-05-15 19:24:15 +00:00
new NetworkCompanyPasswordWindow ( & _ncp_window_desc , parent ) ;
2007-12-02 14:48:26 +00:00
}
2004-12-04 17:54:56 +00:00
# endif /* ENABLE_NETWORK */