# network_gui.cpp File Reference

Implementation of the Network related GUIs. More...

`#include "../stdafx.h"`
`#include "../strings_func.h"`
`#include "../date_func.h"`
`#include "../fios.h"`
`#include "network_client.h"`
`#include "network_gui.h"`
`#include "network_gamelist.h"`
`#include "network.h"`
`#include "network_base.h"`
`#include "../gui.h"`
`#include "network_udp.h"`
`#include "../window_func.h"`
`#include "../gfx_func.h"`
`#include "../widgets/dropdown_func.h"`
`#include "../querystring_gui.h"`
`#include "../sortlist_type.h"`
`#include "../company_func.h"`
`#include "../core/geometry_func.hpp"`
`#include "../newgrf_text.h"`
`#include "../genworld.h"`
`#include "table/strings.h"`
`#include "../table/sprites.h"`

Go to the source code of this file.

## Data Structures
class | NWidgetServerListHeader
| Full blown container to make it behave exactly as we want :). More...
class | NetworkGameWindow
struct | NetworkStartServerWindow
struct | NetworkLobbyWindow
struct | NetworkClientListPopupWindow
| Popup selection window to chose an action to perform. More...
struct | NetworkClientListPopupWindow::ClientListAction
| Container for actions that can be executed. More...
struct | NetworkClientListWindow
| Main handle for clientlist. More...
struct | NetworkJoinStatusWindow
struct | NetworkCompanyPasswordWindow
## Typedefs
typedef GUIList < NetworkGameList * > | GUIGameServerList
typedef uint16 | ServerListPosition
typedef void | ClientList_Action_Proc (byte client_no)
## Enumerations
enum | NetworkGameWindowWidgets { NGWW_MAIN, NGWW_CONNECTION, NGWW_CONN_BTN, NGWW_CLIENT_LABEL, NGWW_CLIENT, NGWW_HEADER, NGWW_NAME, NGWW_CLIENTS, NGWW_MAPSIZE, NGWW_DATE, NGWW_YEARS, NGWW_INFO, NGWW_MATRIX, NGWW_SCROLLBAR, NGWW_LASTJOINED_LABEL, NGWW_LASTJOINED, NGWW_DETAILS, NGWW_DETAILS_SPACER, NGWW_JOIN, NGWW_REFRESH, NGWW_NEWGRF, NGWW_NEWGRF_SEL, NGWW_FIND, NGWW_ADD, NGWW_START, NGWW_CANCEL }
| Enum for NetworkGameWindow, referring to _network_game_window_widgets. More...
enum | NetworkStartServerWidgets { NSSW_BACKGROUND, NSSW_GAMENAME_LABEL, NSSW_GAMENAME, NSSW_SETPWD, NSSW_CONNTYPE_LABEL, NSSW_CONNTYPE_BTN, NSSW_CLIENTS_LABEL, NSSW_CLIENTS_BTND, NSSW_CLIENTS_TXT, NSSW_CLIENTS_BTNU, NSSW_COMPANIES_LABEL, NSSW_COMPANIES_BTND, NSSW_COMPANIES_TXT, NSSW_COMPANIES_BTNU, NSSW_SPECTATORS_LABEL, NSSW_SPECTATORS_BTND, NSSW_SPECTATORS_TXT, NSSW_SPECTATORS_BTNU, NSSW_LANGUAGE_LABEL, NSSW_LANGUAGE_BTN, NSSW_GENERATE_GAME, NSSW_LOAD_GAME, NSSW_PLAY_SCENARIO, NSSW_PLAY_HEIGHTMAP, NSSW_CANCEL }
| Enum for NetworkStartServerWindow, referring to _network_start_server_window_widgets. More...
enum | NetworkLobbyWindowWidgets { NLWW_BACKGROUND, NLWW_TEXT, NLWW_HEADER, NLWW_MATRIX, NLWW_SCROLLBAR, NLWW_DETAILS, NLWW_JOIN, NLWW_NEW, NLWW_SPECTATE, NLWW_REFRESH, NLWW_CANCEL }
| Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets. More...
enum | ClientListWidgets { CLW_PANEL }
| Widget numbers of the client list window. More...
enum | NetworkJoinStatusWidgets { NJSW_BACKGROUND, NJSW_CANCELOK }
| Widgets used for the join status window. More...
enum | NetworkCompanyPasswordWindowWidgets { NCPWW_BACKGROUND, NCPWW_LABEL, NCPWW_PASSWORD, NCPWW_SAVE_AS_DEFAULT_PASSWORD, NCPWW_CANCEL, NCPWW_OK }
| Enum for NetworkGameWindow, referring to _network_game_window_widgets. More...
## Functions
static void | ShowNetworkStartServerWindow ()
static void | ShowNetworkLobbyWindow (NetworkGameList *ngl)
| Show the networklobbywindow with the selected server.
void | SwitchToMode (SwitchMode new_mode)
void | SortNetworkLanguages ()
void | UpdateNetworkGameWindow (bool unselect)
| Update the network new window because a new server is found on the network.
static NWidgetBase * | MakeResizableHeader (int *biggest_index)
void | ShowNetworkGameWindow ()
NetworkCompanyInfo * | GetLobbyCompanyInfo (CompanyID company)
| Get the company information of a given company to fill for the lobby.
void | DrawCompanyIcon (CompanyID cid, int x, int y)
| Draw the icon of a company.
static NetworkClientInfo * | NetworkFindClientInfo (byte client_no)
static void | ClientList_Kick (byte client_no)
static void | ClientList_Ban (byte client_no)
static void | ClientList_GiveMoney (byte client_no)
static void | ClientList_SpeakToClient (byte client_no)
static void | ClientList_SpeakToCompany (byte client_no)
static void | ClientList_SpeakToAll (byte client_no)
static void | PopupClientList (int client_no, int x, int y)
| Show the popup (action list).
void | ShowClientList ()
void | ShowJoinStatusWindow ()
void | ShowNetworkNeedPassword (NetworkPasswordType npt)
void | ShowNetworkCompanyPasswordWindow (Window *parent)
## Variables
static const StringID | _connection_types_dropdown []
static const StringID | _lan_internet_types_dropdown []
static StringID | _language_dropdown [NETLANG_COUNT+1] = {STR_NULL}
static const ServerListPosition | SLP_INVALID = 0xFFFF
static const NWidgetPart | _nested_network_game_widgets []
static const WindowDesc | _network_game_window_desc (WDP_CENTER, 1000, 730, WC_NETWORK_WINDOW, WC_NONE, WDF_UNCLICK_BUTTONS, _nested_network_game_widgets, lengthof(_nested_network_game_widgets))
static const NWidgetPart | _nested_network_start_server_window_widgets []
static const WindowDesc | _network_start_server_window_desc (WDP_CENTER, 0, 0, WC_NETWORK_WINDOW, WC_NONE, WDF_UNCLICK_BUTTONS, _nested_network_start_server_window_widgets, lengthof(_nested_network_start_server_window_widgets))
static const NWidgetPart | _nested_network_lobby_window_widgets []
static const WindowDesc | _network_lobby_window_desc (WDP_CENTER, 0, 0, WC_NETWORK_WINDOW, WC_NONE, WDF_UNCLICK_BUTTONS, _nested_network_lobby_window_widgets, lengthof(_nested_network_lobby_window_widgets))
static const NWidgetPart | _nested_client_list_popup_widgets []
static const WindowDesc | _client_list_popup_desc (WDP_AUTO, 0, 0, WC_TOOLBAR_MENU, WC_CLIENT_LIST, 0, _nested_client_list_popup_widgets, lengthof(_nested_client_list_popup_widgets))
static const NWidgetPart | _nested_client_list_widgets []
static const WindowDesc | _client_list_desc (WDP_AUTO, 0, 0, WC_CLIENT_LIST, WC_NONE, 0, _nested_client_list_widgets, lengthof(_nested_client_list_widgets))
NetworkJoinStatus | _network_join_status
uint8 | _network_join_waiting
uint32 | _network_join_bytes
uint32 | _network_join_bytes_total
static const NWidgetPart | _nested_network_join_status_window_widgets []
static const WindowDesc | _network_join_status_window_desc (WDP_CENTER, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WDF_MODAL, _nested_network_join_status_window_widgets, lengthof(_nested_network_join_status_window_widgets))
static const NWidgetPart | _nested_network_company_password_window_widgets []
static const WindowDesc | _network_company_password_window_desc (WDP_AUTO, 0, 0, WC_COMPANY_PASSWORD_WINDOW, WC_NONE, WDF_UNCLICK_BUTTONS, _nested_network_company_password_window_widgets, lengthof(_nested_network_company_password_window_widgets))

## Detailed Description

Implementation of the Network related GUIs.

Definition in file network_gui.cpp.

## Enumeration Type Documentation

enum ClientListWidgets

Widget numbers of the client list window.

Definition at line 1898 of file network_gui.cpp.

enum NetworkCompanyPasswordWindowWidgets

Enum for NetworkGameWindow, referring to _network_game_window_widgets.

Enumerator:

  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.

Definition at line 2212 of file network_gui.cpp.

enum NetworkGameWindowWidgets

Enum for NetworkGameWindow, referring to _network_game_window_widgets.

Enumerator:

  NGWW_MAIN | Main panel.
  NGWW_CONNECTION | Label in front of connection droplist.
  NGWW_CONN_BTN | 'Connection' droplist button
  NGWW_CLIENT_LABEL | Label in front of client name edit box.
  NGWW_CLIENT | Panel with editbox to set client name.
  NGWW_HEADER | Header container of the matrix.
  NGWW_NAME | 'Name' button
  NGWW_CLIENTS | 'Clients' button
  NGWW_MAPSIZE | 'Map size' button
  NGWW_DATE | 'Date' button
  NGWW_YEARS | 'Years' button
  NGWW_INFO | Third button in the game list panel.
  NGWW_MATRIX | Panel with list of games.
  NGWW_SCROLLBAR | Scrollbar of matrix.
  NGWW_LASTJOINED_LABEL | Label "Last joined server:".
  NGWW_LASTJOINED | Info about the last joined server.
  NGWW_DETAILS | Panel with game details.
  NGWW_DETAILS_SPACER | Spacer for game actual details.
  NGWW_JOIN | 'Join game' button
  NGWW_REFRESH | 'Refresh server' button
  NGWW_NEWGRF | 'NewGRF Settings' button
  NGWW_NEWGRF_SEL | Selection 'widget' to hide the NewGRF settings.
  NGWW_FIND | 'Find server' button
  NGWW_ADD | 'Add server' button
  NGWW_START | 'Start server' button
  NGWW_CANCEL | 'Cancel' button

Definition at line 79 of file network_gui.cpp.

enum NetworkJoinStatusWidgets

Widgets used for the join status window.

Enumerator:

  NJSW_BACKGROUND | Background.
  NJSW_CANCELOK | Cancel/OK button.

Definition at line 2071 of file network_gui.cpp.

enum NetworkLobbyWindowWidgets

Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets.

Enumerator:

  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

Definition at line 1370 of file network_gui.cpp.

enum NetworkStartServerWidgets

Enum for NetworkStartServerWindow, referring to _network_start_server_window_widgets.

Enumerator:

  NSSW_GAMENAME | Background for editbox to set game name.
  NSSW_SETPWD | 'Set password' button
  NSSW_CONNTYPE_BTN | 'Connection type' droplist button
  NSSW_CLIENTS_BTND | 'Max clients' downarrow
  NSSW_CLIENTS_TXT | 'Max clients' text
  NSSW_CLIENTS_BTNU | 'Max clients' uparrow
  NSSW_COMPANIES_BTND | 'Max companies' downarrow
  NSSW_COMPANIES_TXT | 'Max companies' text
  NSSW_COMPANIES_BTNU | 'Max companies' uparrow
  NSSW_SPECTATORS_BTND | 'Max spectators' downarrow
  NSSW_SPECTATORS_TXT | 'Max spectators' text
  NSSW_SPECTATORS_BTNU | 'Max spectators' uparrow
  NSSW_LANGUAGE_BTN | 'Language spoken' droplist button
  NSSW_GENERATE_GAME | New game button.
  NSSW_LOAD_GAME | Load game button.
  NSSW_PLAY_SCENARIO | Play scenario button.
  NSSW_PLAY_HEIGHTMAP | Play heightmap button.
  NSSW_CANCEL | 'Cancel' button

Definition at line 1011 of file network_gui.cpp.

## Function Documentation

void DrawCompanyIcon | ( | CompanyID | c,
|  | int | x,
|  | int | y |
| ) |  |  |

Draw the icon of a company.

Parameters:

  | c | Company that needs its icon drawn.
  | x | Horizontal coordinate of the icon.
  | y | Vertical coordinate of the icon.

Definition at line 135 of file company_cmd.cpp.

References DrawSprite().

Referenced by TownAuthorityWindow::DrawRatings(), SignListWindow::DrawWidget(), NetworkClientListWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), CompanyLeagueWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), CheatWindow::DrawWidget(), and AIDebugWindow::OnPaint().

NetworkCompanyInfo* GetLobbyCompanyInfo | ( | CompanyID | company | ) |

Get the company information of a given company to fill for the lobby.

Parameters:

  | company | the company to get the company info struct from.

Returns:
  the company info struct to write the (downloaded) data to.

Definition at line 1684 of file network_gui.cpp.

References FindWindowById().

Referenced by NetworkLobbyWindow::OnPaint().

static void ShowNetworkLobbyWindow | ( | NetworkGameList * | ngl | ) | `[static]`

Show the networklobbywindow with the selected server.

Parameters:

  | ngl | Selected game pointer which is passed to the new window.

Definition at line 1669 of file network_gui.cpp.

References _settings_client, DeleteWindowById(), NetworkSettings::last_host, NetworkSettings::last_port, and ClientSettings::network.

Referenced by NetworkGameWindow::OnClick().

void UpdateNetworkGameWindow | ( | bool | unselect | ) |

Update the network new window because a new server is found on the network.

Parameters:

  | unselect | unselect the currently selected item

Definition at line 73 of file network_gui.cpp.

References InvalidateWindowData().

Referenced by NetworkGameListAddItem(), NetworkGameListHandleDelayedInsert(), and NetworkGameListRemoveItem().

## Variable Documentation

const StringID _connection_types_dropdown[]`[static]`

Initial value:

     {
      STR_NETWORK_START_SERVER_LAN_INTERNET,
      STR_NETWORK_START_SERVER_INTERNET_ADVERTISE,
      INVALID_STRING_ID
    }

Definition at line 42 of file network_gui.cpp.

const StringID _lan_internet_types_dropdown[]`[static]`

Initial value:

     {
      STR_NETWORK_SERVER_LIST_LAN,
      STR_NETWORK_SERVER_LIST_INTERNET,
      INVALID_STRING_ID
    }

Definition at line 48 of file network_gui.cpp.

const NWidgetPart _nested_client_list_popup_widgets[]`[static]`

Initial value:

     {
      NWidget(WWT_PANEL, COLOUR_GREY, 0), EndContainer(),
    }

Definition at line 1699 of file network_gui.cpp.

const NWidgetPart _nested_client_list_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_GREY),
        NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
        NWidget(WWT_STICKYBOX, COLOUR_GREY),
      EndContainer(),
      NWidget(WWT_PANEL, COLOUR_GREY, CLW_PANEL), SetMinimalSize(250, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM), SetResize(1, 1), EndContainer(),
    }

Definition at line 1902 of file network_gui.cpp.

const NWidgetPart _nested_network_company_password_window_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_CLOSEBOX, COLOUR_GREY),
        NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_PASSWORD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
      EndContainer(),
      NWidget(WWT_PANEL, COLOUR_GREY, NCPWW_BACKGROUND),
        NWidget(NWID_VERTICAL), SetPIP(5, 5, 5),
          NWidget(NWID_HORIZONTAL), SetPIP(5, 5, 5),
            NWidget(WWT_TEXT, COLOUR_GREY, NCPWW_LABEL), SetDataTip(STR_COMPANY_VIEW_PASSWORD, STR_NULL),
            NWidget(WWT_EDITBOX, COLOUR_GREY, NCPWW_PASSWORD), SetMinimalSize(194, 12), SetDataTip(STR_COMPANY_VIEW_SET_PASSWORD, STR_NULL),
          EndContainer(),
          NWidget(NWID_HORIZONTAL), SetPIP(5, 0, 5),
            NWidget(NWID_SPACER), SetFill(1, 0),
            NWidget(WWT_TEXTBTN, COLOUR_GREY, NCPWW_SAVE_AS_DEFAULT_PASSWORD), SetMinimalSize(194, 12),
                          SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
          EndContainer(),
        EndContainer(),
      EndContainer(),
      NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, NCPWW_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL),
        NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, NCPWW_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK),
      EndContainer(),
    }

Definition at line 2293 of file network_gui.cpp.

const NWidgetPart _nested_network_join_status_window_widgets[]`[static]`

Initial value:

     {
      NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_CONNECTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
      NWidget(WWT_PANEL, COLOUR_GREY),
        NWidget(WWT_EMPTY, COLOUR_GREY, NJSW_BACKGROUND),
        NWidget(NWID_HORIZONTAL),
          NWidget(NWID_SPACER), SetMinimalSize(75, 0), SetFill(1, 0),
          NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NJSW_CANCELOK), SetMinimalSize(101, 12), SetDataTip(STR_NETWORK_CONNECTION_DISCONNECT, STR_NULL),
          NWidget(NWID_SPACER), SetMinimalSize(75, 0), SetFill(1, 0),
        EndContainer(),
        NWidget(NWID_SPACER), SetMinimalSize(0, 4),
      EndContainer(),
    }

Definition at line 2169 of file network_gui.cpp.