Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../date_func.h"
22 #include "../window_func.h"
23 #include "../gfx_func.h"
24 #include "../widgets/dropdown_func.h"
25 #include "../querystring_gui.h"
26 #include "../sortlist_type.h"
27 #include "../company_func.h"
28 #include "../core/geometry_func.hpp"
29 #include "../genworld.h"
30 #include "../map_type.h"
31 #include "../guitimer_func.h"
32 #include "../zoom_func.h"
34 #include "../widgets/network_widget.h"
36 #include "table/strings.h"
37 #include "../table/sprites.h"
39 #include "../stringfilter_type.h"
41 #include "../safeguards.h"
44 # include <emscripten.h>
47 static void ShowNetworkStartServerWindow();
54 STR_NETWORK_START_SERVER_UNADVERTISED,
55 STR_NETWORK_START_SERVER_ADVERTISED,
59 static std::vector<StringID> _language_dropdown;
61 void SortNetworkLanguages()
64 if (_language_dropdown.empty()) {
65 for (
int i = 0; i < NETLANG_COUNT; i++) _language_dropdown.emplace_back(STR_NETWORK_LANG_ANY + i);
70 std::sort(_language_dropdown.begin() + 1, _language_dropdown.end() - 1, StringIDSorter);
83 typedef uint16 ServerListPosition;
84 static const ServerListPosition SLP_INVALID = 0xFFFF;
109 this->visible[0] =
true;
110 *
lastof(this->visible) =
true;
125 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
126 child_wid->SetupSmallestSize(w, init_array);
127 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
131 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
132 child_wid->current_x = child_wid->smallest_x;
151 for (uint i = 1; i <
lengthof(this->visible) - 1; i++) {
153 this->visible[i] =
true;
156 this->visible[i] =
false;
158 child_wid = child_wid->
next;
166 uint i = rtl ?
lengthof(this->visible) - 1 : 0;
167 child_wid = rtl ? this->
tail : this->
head;
168 while (child_wid !=
nullptr) {
169 if (this->visible[i]) {
174 child_wid = rtl ? child_wid->
prev : child_wid->
next;
182 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
183 if (!this->visible[i++])
continue;
194 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
195 if (!this->visible[i++])
continue;
197 if (nwid !=
nullptr)
return nwid;
246 this->servers.clear();
249 this->servers.push_back(ngl);
263 this->servers.shrink_to_fit();
265 this->vscroll->
SetCount((
int)this->servers.size());
268 this->servers.
Sort();
348 this->list_pos = SLP_INVALID;
349 for (uint i = 0; i != this->servers.size(); i++) {
350 if (this->servers[i] == this->server) {
359 assert(item !=
nullptr);
360 assert((*item) !=
nullptr);
363 sf.
AddLine((*item)->info.server_name);
448 if (this->list_pos == SLP_INVALID)
return;
455 this->list_pos = SLP_INVALID;
456 this->server =
nullptr;
458 this->lock_offset = 5;
459 this->blot_offset = this->lock_offset + 3 +
GetSpriteSize(SPR_LOCK).width;
460 this->flag_offset = this->blot_offset + 2 +
GetSpriteSize(SPR_BLOT).width;
477 #ifdef __EMSCRIPTEN__
478 EM_ASM(
if (window[
"openttd_server_list"]) openttd_server_list());
495 this->last_sorting = this->servers.
GetListing();
503 fill->height =
resize->height;
504 size->height = 12 *
resize->height;
512 size->width = NWidgetScrollbar::GetVerticalDimension().width;
550 const int max = std::min(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), (
int)this->servers.size());
552 for (
int i = this->vscroll->
GetPosition(); i < max; ++i) {
562 if (this->last_joined !=
nullptr) this->
DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
566 this->DrawDetails(r);
603 #ifdef __EMSCRIPTEN__
613 void DrawDetails(
const Rect &r)
const
621 if (sel ==
nullptr) {
623 }
else if (!sel->
online) {
633 uint16 y = r.top + detail_height + 4;
701 if (this->list_pos != SLP_INVALID) this->list_pos = (ServerListPosition)this->servers.size() - this->list_pos - 1;
713 this->server = (id_v < this->servers.size()) ? this->servers[id_v] :
nullptr;
714 this->list_pos = (
server ==
nullptr) ? SLP_INVALID : id_v;
723 if (this->last_joined !=
nullptr) {
749 STR_NETWORK_SERVER_LIST_ENTER_IP,
755 ShowNetworkStartServerWindow();
759 if (this->server !=
nullptr) {
796 if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
797 if (this->servers.size() == 0)
return ES_HANDLED;
801 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
802 if (this->list_pos > 0) this->list_pos--;
806 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
807 if (this->list_pos < this->
servers.size() - 1) this->list_pos++;
811 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
812 this->list_pos = (this->list_pos < this->vscroll->
GetCapacity()) ? 0 : this->list_pos - this->vscroll->
GetCapacity();
816 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
817 this->list_pos = std::min(this->list_pos + this->vscroll->
GetCapacity(), (
int)this->servers.size() - 1);
825 this->list_pos = (ServerListPosition)this->servers.size() - 1;
827 default: NOT_REACHED();
830 this->server = this->servers[this->
list_pos];
840 if (this->server !=
nullptr) {
841 if (keycode == WKC_DELETE) {
843 if (this->server == this->last_joined) this->last_joined =
nullptr;
844 this->server =
nullptr;
845 this->list_pos = SLP_INVALID;
865 if (!
StrEmpty(this->name_editbox.text.
buf) && this->name_editbox.text.buf[0] !=
' ') {
876 if (!
StrEmpty(str)) NetworkAddServer(str);
886 if (!this->requery_timer.
Elapsed(delta_ms))
return;
893 Listing NetworkGameWindow::last_sorting = {
false, 5};
907 static NWidgetBase *MakeResizableHeader(
int *biggest_index)
909 *biggest_index = std::max<int>(*biggest_index,
WID_NG_INFO);
913 static const NWidgetPart _nested_network_game_widgets[] = {
928 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
943 SetDataTip(0x0, STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST),
954 SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
958 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_NG_DETAILS_SPACER),
SetMinimalSize(140, 0),
SetMinimalTextLines(15, 24 +
WD_PAR_VSEP_NORMAL),
SetResize(0, 1),
SetFill(1, 1),
1005 _nested_network_game_widgets,
lengthof(_nested_network_game_widgets)
1008 void ShowNetworkGameWindow()
1010 static bool first =
true;
1019 NetworkAddServer(iter.c_str());
1070 size->width += padding.width;
1071 size->height += padding.height;
1089 ShowNetworkGameWindow();
1110 default: NOT_REACHED();
1145 for (uint i = 0; i < _language_dropdown.size() - 1; i++) {
1207 for (
const int *widget = raise_widgets; *widget !=
WIDGET_LIST_END; widget++) {
1217 if (str ==
nullptr)
return;
1222 int32 value = atoi(str);
1224 switch (this->widget_id) {
1225 default: NOT_REACHED();
1236 static const NWidgetPart _nested_network_start_server_window_widgets[] = {
1316 static WindowDesc _network_start_server_window_desc(
1320 _nested_network_start_server_window_widgets,
lengthof(_nested_network_start_server_window_widgets)
1323 static void ShowNetworkStartServerWindow()
1345 CompanyID NetworkLobbyFindCompanyIndex(
byte pos)
const
1349 if (!
StrEmpty(this->company_info[i].company_name)) {
1350 if (pos-- == 0)
return i;
1366 size->height = 10 *
resize->height;
1388 this->DrawDetails(r);
1392 this->DrawMatrix(r);
1414 void DrawMatrix(
const Rect &r)
const
1422 int lock_width = lock_size.width;
1426 int profit_width = lock_size.width;
1429 uint text_left =
left + (rtl ? lock_width + profit_width + 4 : 0);
1430 uint text_right = right - (rtl ? 0 : lock_width + profit_width + 4);
1431 uint profit_left = rtl ?
left : right - profit_width;
1432 uint lock_left = rtl ?
left + profit_width + 2 : right - profit_width - lock_width - 2;
1438 byte company = NetworkLobbyFindCompanyIndex(pos);
1439 bool income =
false;
1440 if (this->company ==
company) {
1444 DrawString(text_left, text_right, y + text_offset, this->company_info[
company].company_name, TC_BLACK);
1445 if (this->company_info[
company].use_password != 0)
DrawSprite(SPR_LOCK, PAL_NONE, lock_left, y + lock_y_offset);
1448 if (this->company_info[
company].income >= 0) income =
true;
1449 DrawSprite(income ? SPR_PROFIT_LOT : SPR_PROFIT_NEGATIVE, PAL_NONE, profit_left, y + profit_y_offset);
1453 if (pos >= this->vscroll->
GetPosition() + this->vscroll->GetCapacity())
break;
1457 void DrawDetails(
const Rect &r)
const
1466 int y = r.top + detail_height + 4;
1476 SetDParamStr(0, this->company_info[this->company].company_name);
1480 SetDParam(0, this->company_info[this->company].inaugurated_year);
1484 SetDParam(0, this->company_info[this->company].company_value);
1488 SetDParam(0, this->company_info[this->company].money);
1492 SetDParam(0, this->company_info[this->company].income);
1496 SetDParam(0, this->company_info[this->company].performance);
1500 SetDParam(0, this->company_info[this->company].num_vehicle[NETWORK_VEH_TRAIN]);
1501 SetDParam(1, this->company_info[this->company].num_vehicle[NETWORK_VEH_LORRY]);
1502 SetDParam(2, this->company_info[this->company].num_vehicle[NETWORK_VEH_BUS]);
1503 SetDParam(3, this->company_info[this->company].num_vehicle[NETWORK_VEH_SHIP]);
1504 SetDParam(4, this->company_info[this->company].num_vehicle[NETWORK_VEH_PLANE]);
1508 SetDParam(0, this->company_info[this->company].num_station[NETWORK_VEH_TRAIN]);
1509 SetDParam(1, this->company_info[this->company].num_station[NETWORK_VEH_LORRY]);
1510 SetDParam(2, this->company_info[this->company].num_station[NETWORK_VEH_BUS]);
1511 SetDParam(3, this->company_info[this->company].num_station[NETWORK_VEH_SHIP]);
1512 SetDParam(4, this->company_info[this->company].num_station[NETWORK_VEH_PLANE]);
1516 SetDParamStr(0, this->company_info[this->company].clients);
1524 ShowNetworkGameWindow();
1565 static const NWidgetPart _nested_network_lobby_window_widgets[] = {
1571 NWidget(
WWT_TEXT, COLOUR_LIGHT_BLUE,
WID_NL_TEXT),
SetDataTip(STR_NETWORK_GAME_LOBBY_PREPARE_TO_JOIN, STR_NULL),
SetResize(1, 0),
SetPadding(10, 10, 0, 10),
1576 NWidget(
WWT_PANEL, COLOUR_WHITE,
WID_NL_HEADER),
SetMinimalSize(146, 0),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
1577 NWidget(
WWT_MATRIX, COLOUR_LIGHT_BLUE,
WID_NL_MATRIX),
SetMinimalSize(146, 0),
SetResize(1, 1),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_NETWORK_GAME_LOBBY_COMPANY_LIST_TOOLTIP),
SetScrollbar(
WID_NL_SCROLLBAR),
1582 NWidget(
WWT_PANEL, COLOUR_LIGHT_BLUE,
WID_NL_DETAILS),
SetMinimalSize(232, 0),
SetResize(1, 1),
SetFill(1, 1),
EndContainer(),
1604 static WindowDesc _network_lobby_window_desc(
1608 _nested_network_lobby_window_widgets,
lengthof(_nested_network_lobby_window_widgets)
1634 return (lobby !=
nullptr && company <
MAX_COMPANIES) ? &lobby->company_info[company] :
nullptr;
1648 static const NWidgetPart _nested_client_list_popup_widgets[] = {
1656 _nested_client_list_popup_widgets,
lengthof(_nested_client_list_popup_widgets)
1695 Point desired_location;
1705 this->actions.push_back({name, proc});
1710 sel_index(0), client_id(client_id)
1712 this->desired_location.x = x;
1713 this->desired_location.y = y;
1718 this->
AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
1722 this->
AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, &ClientList_SpeakToCompany);
1724 this->
AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, &ClientList_SpeakToAll);
1728 this->
AddAction(STR_NETWORK_CLIENTLIST_KICK, &ClientList_Kick);
1729 this->
AddAction(STR_NETWORK_CLIENTLIST_BAN, &ClientList_Ban);
1738 return this->desired_location;
1748 d.height *= (uint)this->actions.size();
1757 int sel = this->sel_index;
1779 if (index == this->sel_index || index >= this->actions.size())
return;
1781 this->sel_index = index;
1784 if (index < this->
actions.size() && _cursor.
pos.y >= this->top) {
1786 if (ci !=
nullptr) this->actions[index].proc(ci);
1806 static const NWidgetPart _nested_client_list_widgets[] = {
1819 _nested_client_list_widgets,
lengthof(_nested_client_list_widgets)
1828 uint server_client_width;
1852 num *= this->line_height;
1892 int icon_offset = (this->line_height - icon_size.height) / 2;
1898 uint type_icon_width = this->server_client_width + this->icon_size.width +
WD_FRAMERECT_LEFT;
1901 uint type_left = rtl ? right - this->server_client_width :
left;
1902 uint type_right = rtl ? right :
left + this->server_client_width - 1;
1903 uint icon_left = rtl ? right - type_icon_width +
WD_FRAMERECT_LEFT :
left + this->server_client_width;
1904 uint name_left = rtl ?
left :
left + type_icon_width;
1905 uint name_right = rtl ? right - type_icon_width : right;
1910 if (this->selected_item == i++) {
1918 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_SERVER, colour);
1920 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_CLIENT, colour);
1935 if (this->selected_item != -1) {
1936 int client_no = this->selected_item;
1938 if (client_no == 0) {
1951 this->selected_item = -1;
1957 pt.y -= this->GetWidget<NWidgetBase>(
WID_CL_PANEL)->pos_y;
1964 if (item == this->selected_item)
return;
1965 this->selected_item = item;
1972 void ShowClientList()
1974 AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
1998 case NETWORK_JOIN_STATUS_CONNECTING:
case NETWORK_JOIN_STATUS_AUTHORIZING:
1999 case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
2002 case NETWORK_JOIN_STATUS_WAITING:
2007 case NETWORK_JOIN_STATUS_DOWNLOADING:
2022 DrawFrameRect(r.left + 20, r.top + 5, (
int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
2033 for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
2056 ShowNetworkGameWindow();
2064 ShowNetworkGameWindow();
2068 switch (this->password_type) {
2071 default: NOT_REACHED();
2076 static const NWidgetPart _nested_network_join_status_window_widgets[] = {
2089 static WindowDesc _network_join_status_window_desc(
2093 _nested_network_join_status_window_widgets,
lengthof(_nested_network_join_status_window_widgets)
2096 void ShowJoinStatusWindow()
2105 if (w ==
nullptr)
return;
2106 w->password_type = npt;
2110 default: NOT_REACHED();
2124 this->UpdateWarningStringSize();
2133 void UpdateWarningStringSize()
2137 this->warning_size.height =
GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width);
2156 STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING,
SA_CENTER);
2187 static const NWidgetPart _nested_network_company_password_window_widgets[] = {
2201 SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
2212 static WindowDesc _network_company_password_window_desc(
2216 _nested_network_company_password_window_widgets,
lengthof(_nested_network_company_password_window_widgets)
2219 void ShowNetworkCompanyPasswordWindow(
Window *parent)
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
@ ES_HANDLED
The passed event is handled.
static bool NGameAllowedSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by joinability.
uint32 _network_join_bytes_total
The total number of bytes to download.
The game information that is sent from the server to the clients.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
QueryString name_editbox
Client name editbox.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void NetworkTCPQueryServer(NetworkAddress address)
Query a server to fetch his game-info.
@ FT_SCENARIO
old or new scenario
uint8 SortType() const
Get the sorttype of the list.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
char32_t WChar
Type for wide characters, i.e.
uint8 max_spectators
maximum amount of spectators
@ QSF_PASSWORD
password entry box, show warning about password security
Dimensions (a width and height) of a rectangle in 2D.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
NWidgetBase * nested_root
Root of the nested tree.
bool Sort(Comp compare)
Sort the list.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
byte companies_max
Max companies allowed on server.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void OnResize() override
Called after the window got resized.
uint8 _network_join_waiting
The number of clients waiting in front of us.
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Scrollbar * vscroll
vertical scrollbar of the list of servers
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
bool IsEmpty() const
Check whether any filter words were entered.
bool _left_button_down
Is left mouse button pressed?
uint8 max_clients
maximum amount of clients
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
uint8 server_lang
language of the server
void SetFilterTerm(const char *str)
Set the term to filter on.
static const StringID _connection_types_dropdown[]
Advertisement options in the start server window.
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
CompanyID client_playas
As which company is this client playing (CompanyID)
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
char connect_to_ip[NETWORK_HOSTNAME_LENGTH]
default for the "Add server" query
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool _network_server
network-server is active
void Assign(StringID string)
Render a string into the textbuffer.
NetworkGameList * NetworkGameListAddItem(NetworkAddress address)
Add a new item to the linked gamelist.
void SortNetworkGameList()
Sort the server list.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
Show the networklobbywindow with the selected server.
@ WC_CLIENT_LIST
Client list; Window numbers:
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
@ WC_COMPANY_PASSWORD_WINDOW
Company password query; Window numbers:
GUIGameServerList servers
list with game servers.
NetworkJoinStatus
Status of the clients during joining.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
static bool NGameNameSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by name.
@ WC_CLIENT_LIST_POPUP
Popup for the client list; Window numbers:
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
QueryString password_editbox
Password editbox.
bool _ctrl_pressed
Is Ctrl pressed?
static const uint MAX_CLIENTS
How many clients can we have.
bool use_password
Is this server passworded?
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
ClientSettings _settings_client
The current settings for this game.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
void NetworkUDPSearchGame()
Find all servers.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
uint16 map_width
Map width.
NetworkJoinStatus _network_join_status
The status of joining.
int32 WindowNumber
Number to differentiate different windows of the same class.
@ SA_CENTER
Center both horizontally and vertically.
NetworkAddress address
The connection info of the game server.
@ SA_HOR_CENTER
Horizontally center the text.
static bool NGameClientSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the amount of clients online on a server.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
Owner
Enum for all companies/owners.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
bool version_compatible
Can we connect to this server or not? (based on server_revision)
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Data stored about a string that can be modified in the GUI.
NetworkGameList * server
Selected server.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
char *const buf
buffer in which text is saved
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
NetworkGameList * _network_game_list
Game list of this client.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
High level window description.
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
Query a specific server.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ COMPANY_FIRST
First company, same as owner.
void OnResize() override
Called after the window got resized.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
NetworkGameList * last_joined
the last joined server
Date start_date
When the game started.
bool IsDescSortOrder() const
Check if the sort order is descending.
@ COMPANY_NEW_COMPANY
The client wants a new company.
@ WDP_AUTO
Find a place automatically.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Data structure describing how to show the list (what sort direction and criteria).
void SetFilterState(bool state)
Enable or disable the filter.
@ SLO_LOAD
File is being loaded.
byte server_lang
Language of the server (we should make a nice table for this)
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
ResizeInfo resize
Resize information.
void NetworkUDPQueryMasterServer()
Request the the server-list from the master server.
void OnPaint() override
The window must be repainted.
Main handle for clientlist.
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
void OnPaint() override
The window must be repainted.
void ShowGenerateLandscape()
Start with a normal game.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
int height
Height of the window (number of pixels down in y direction)
@ WN_NETWORK_WINDOW_START
Network start server.
QueryString name_editbox
Server name editbox.
byte companies_on
How many started companies do we have.
@ WF_WHITE_BORDER
Window white border counter bit mask.
CompanyID company
Selected company.
bool SortFunction(const NetworkGameList * &, const NetworkGameList * &)
Signature of sort function.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void SetListing(Listing l)
Import sort conditions.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
static bool NGameDateSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by current date.
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
ClientID
'Unique' identifier to be given to clients
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
QueryString filter_editbox
Editbox for filter on servers.
static bool NGameYearsSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the number of days the game is running.
GUITimer requery_timer
Timer for network requery.
uint16 GetPort() const
Get the port.
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Window * parent
Parent window.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ NETWORK_COMPANY_PASSWORD
The password of the company.
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
int left
x position of left edge of the window
WindowFlags flags
Window flags.
@ COMPANY_INACTIVE_CLIENT
The client is joining.
@ WF_TIMEOUT
Window timeout counter.
@ CLIENT_ID_SERVER
Servers always have this ID.
@ WN_NETWORK_WINDOW_GAME
Network game window.
int blot_offset
Left offset for green/yellow/red compatibility icon.
bool CheckClientListHeight()
Finds the amount of clients and set the height correct.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
uint16 last_port
port of the last joined server
void BuildGUINetworkGameList()
(Re)build the GUI network game list (a.k.a.
byte widget_id
The widget that has the pop-up input menu.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Coordinates of a point in 2D.
char server_name[NETWORK_NAME_LENGTH]
name of the server
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
static void PopupClientList(ClientID client_id, int x, int y)
Show the popup (action list)
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
char server_name[NETWORK_NAME_LENGTH]
Server name.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
@ FT_SAVEGAME
old or new savegame
static const uint8 PC_BLACK
Black palette colour.
WindowNumber window_number
Window number within the window class.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
uint step_height
Step-size of height resize changes.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
void OnTimeout() override
Called when this window's timeout has been reached.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
ClientID client_id
Client identifier (same as ClientState->client_id)
static const uint8 PC_GREY
Grey palette colour.
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
ClientID _network_own_client_id
Our client identifier.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
bool server_advertise
advertise the server to the masterserver
void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
Draw a single server line.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool NeedRebuild() const
Check if a rebuild is needed.
void NetworkServerKickClient(ClientID client_id, const char *reason)
Kick a single client.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void ScrollToSelectedServer()
Scroll the list up or down to the currently selected server.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
NetworkGameList * server
selected server
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
byte clients_max
Max clients allowed on server.
@ WD_BEVEL_RIGHT
Width of right bevel border.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
@ COMPANY_SPECTATOR
The client is spectating.
@ WC_NETWORK_WINDOW
Network window; Window numbers:
bool CDECL FilterFunction(const NetworkGameList * *, StringFilter &)
Signature of filter function.
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason)
Ban, or kick, everyone joined from the given client's IP.
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
void ResetState()
Reset the matching state to process a new item.
void UpdateListPos()
Set this->list_pos to match this->server.
void ClientList_Action_Proc(const NetworkClientInfo *ci)
Prototype for ClientList actions.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Listing GetListing() const
Export current sort conditions.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
int CompareTo(NetworkAddress &address)
Compare the address of this class with the address of another.
NetworkPasswordType
The type of password we're asking for.
EventState
State of handling an event.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
bool GetState() const
Get the matching state of the current item.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
@ FT_HEIGHTMAP
heightmap file
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
@ SM_MENU
Switch to game intro menu.
static const int ACTION_CLEAR
Clear editbox.
int top
y position of top edge of the window
Date game_date
Current date.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
bool Elapsed(uint delta)
Test if a timer has elapsed.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Structure with information shown in the game list (GUI)
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
void NetworkGameListRequery()
Requeries the (game) servers we have not gotten a reply from.
@ WD_BEVEL_LEFT
Width of left bevel border.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
void ForceRebuild()
Force that a rebuild is needed.
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
Data structure to convert between Date and triplet (year, month, and day).
char server_revision[NETWORK_REVISION_LENGTH]
The version number the server is using (e.g.: 'r304' or 0.5.0)
Dimension warning_size
How much space to use for the warning text.
static const SpriteID SPR_FLAGS_BASE
Flags sprites (in same order as enum NetworkLanguage)
NetworkSettings network
settings related to the network
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
@ WN_NETWORK_WINDOW_LOBBY
Network lobby window.
int lock_offset
Left offset for lock icon.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
@ INVALID_COMPANY
An invalid company.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
byte spectators_on
How many spectators do we have?
NetworkGameList * next
Next pointer to make a linked game list.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
void DrawWidgets() const
Paint all widgets of a window.
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
StringList _network_host_list
The servers we know.
void OnPaint() override
The window must be repainted.
uint16 map_height
Map height.
NetworkGameInfo info
The game information of this server.
byte clients_on
Current count of clients on server.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
GRFConfig * grfconfig
List of NewGRF files used.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
Company information stored at the client side.
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
#define CLRBITS(x, y)
Clears several bits in a variable.
bool online
False if the server did not respond (default status)
#define lastof(x)
Get the last element of an fixed size array.
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
uint32 _network_join_bytes
The number of bytes we already downloaded.
ServerListPosition list_pos
position of the selected server
@ WDP_CENTER
Center the window.
static bool NGameMapSizeSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by map size.
bool _left_button_clicked
Is left mouse button clicked?
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void GetAddressAsString(char *buffer, const char *last, bool with_family=true)
Get the address as a string, e.g.
bool _is_network_server
Does this client wants to be a network-server?
@ CS_NUMERAL
Only numeric ones.
Container for all information known about a client.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
int flag_offset
Left offset for language flag icon.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
@ NETWORK_GAME_PASSWORD
The password of the game.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
byte spectators_max
Max spectators allowed on server.
uint8 max_companies
maximum amount of companies
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
void DrawCompanyIcon(CompanyID cid, int x, int y)
Draw the icon of a company.
byte map_set
Graphical set.