13 #include "../stdafx.h" 14 #include "../strings_func.h" 15 #include "../date_func.h" 25 #include "../window_func.h" 26 #include "../gfx_func.h" 27 #include "../widgets/dropdown_func.h" 28 #include "../querystring_gui.h" 29 #include "../sortlist_type.h" 30 #include "../company_func.h" 31 #include "../core/geometry_func.hpp" 32 #include "../genworld.h" 33 #include "../map_type.h" 35 #include "../widgets/network_widget.h" 37 #include "table/strings.h" 38 #include "../table/sprites.h" 40 #include "../stringfilter_type.h" 42 #include "../safeguards.h" 45 static void ShowNetworkStartServerWindow();
52 STR_NETWORK_START_SERVER_UNADVERTISED,
53 STR_NETWORK_START_SERVER_ADVERTISED,
61 STR_NETWORK_SERVER_LIST_ADVERTISED_NO,
62 STR_NETWORK_SERVER_LIST_ADVERTISED_YES,
66 static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL};
68 void SortNetworkLanguages()
71 if (_language_dropdown[0] == STR_NULL) {
72 for (
int i = 0; i < NETLANG_COUNT; i++) _language_dropdown[i] = STR_NETWORK_LANG_ANY + i;
77 QSortT(_language_dropdown + 1, NETLANG_COUNT - 1, &StringIDSorter);
90 typedef uint16 ServerListPosition;
91 static const ServerListPosition SLP_INVALID = 0xFFFF;
116 this->visible[0] =
true;
117 *
lastof(this->visible) =
true;
132 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
133 child_wid->SetupSmallestSize(w, init_array);
134 this->
smallest_y =
max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
138 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
139 child_wid->current_x = child_wid->smallest_x;
158 for (uint i = 1; i <
lengthof(this->visible) - 1; i++) {
159 if (given_width > MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER + child_wid->
smallest_x && this->visible[i - 1]) {
160 this->visible[i] =
true;
163 this->visible[i] =
false;
165 child_wid = child_wid->
next;
173 uint i = rtl ?
lengthof(this->visible) - 1 : 0;
174 child_wid = rtl ? this->
tail : this->
head;
175 while (child_wid != NULL) {
176 if (this->visible[i]) {
181 child_wid = rtl ? child_wid->
prev : child_wid->
next;
189 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
190 if (!this->visible[i++])
continue;
201 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
202 if (!this->visible[i++])
continue;
204 if (nwid != NULL)
return nwid;
252 this->servers.
Clear();
255 *this->servers.
Append() = ngl;
274 this->servers.
Sort();
275 this->UpdateListPos();
281 int r =
strnatcmp((*a)->info.server_name, (*b)->info.server_name,
true);
282 return r == 0 ? (*a)->address.CompareTo((*b)->address) : r;
293 int r = (*a)->info.clients_on - (*b)->info.clients_on;
295 if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max;
296 if (r == 0) r = NGameNameSorter(a, b);
305 int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width);
307 if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width;
308 return (r != 0) ? r : NGameClientSorter(a, b);
314 int r = (*a)->info.game_date - (*b)->info.game_date;
315 return (r != 0) ? r : NGameClientSorter(a, b);
321 int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
322 return (r != 0) ? r : NGameDateSorter(a, b);
332 int r =
StrEmpty((*a)->info.server_revision) -
StrEmpty((*b)->info.server_revision);
335 if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible;
337 if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible;
339 if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password;
341 if (r == 0) r = -NGameClientSorter(a, b);
349 if (this->servers.
Sort()) this->UpdateListPos();
355 this->list_pos = SLP_INVALID;
356 for (uint i = 0; i != this->servers.
Length(); i++) {
357 if (this->servers[i] == this->server) {
366 assert(item != NULL);
367 assert((*item) != NULL);
370 sf.
AddLine((*item)->info.server_name);
386 if (highlight)
GfxFillRect(nwi_name->
pos_x + 1, y + 1, nwi_info->pos_x + nwi_info->current_x - 2, y + this->resize.step_height - 2,
PC_GREY);
390 int icon_y_offset = (this->resize.step_height -
GetSpriteSize(SPR_BLOT).height) / 2;
430 SetDParam(0, ymd_cur.year - ymd_start.year);
454 if (this->list_pos == SLP_INVALID)
return;
461 this->list_pos = SLP_INVALID;
464 this->lock_offset = 5;
465 this->blot_offset = this->lock_offset + 3 +
GetSpriteSize(SPR_LOCK).width;
466 this->flag_offset = this->blot_offset + 2 +
GetSpriteSize(SPR_BLOT).width;
468 this->CreateNestedTree();
480 this->server = this->last_joined;
491 this->last_sorting = this->servers.
GetListing();
508 size->width += padding.width;
509 size->height += padding.height;
514 size->height = 10 * resize->height;
522 size->width = NWidgetScrollbar::GetVerticalDimension().width;
568 this->DrawServerLine(ngl, y, ngl == this->server);
569 y += this->resize.step_height;
576 if (this->last_joined != NULL) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
580 this->DrawDetails(r);
598 this->BuildGUINetworkGameList();
601 this->SortNetworkGameList();
608 this->SetWidgetDisabledState(
WID_NG_JOIN, sel == NULL ||
620 void DrawDetails(
const Rect &r)
const 630 }
else if (!sel->
online) {
640 uint16 y = r.top + detail_height + 4;
710 if (this->list_pos != SLP_INVALID) this->list_pos = this->servers.
Length() - this->list_pos - 1;
714 this->SortNetworkGameList();
716 this->ScrollToSelectedServer();
722 this->server = (id_v < this->servers.
Length()) ? this->servers[id_v] : NULL;
723 this->list_pos = (server == NULL) ? SLP_INVALID : id_v;
732 if (this->last_joined != NULL) {
733 this->server = this->last_joined;
736 this->UpdateListPos();
737 this->ScrollToSelectedServer();
757 STR_NETWORK_SERVER_LIST_ENTER_IP,
763 ShowNetworkStartServerWindow();
767 if (this->server != NULL) {
818 if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
823 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
824 if (this->list_pos > 0) this->list_pos--;
828 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
829 if (this->list_pos < this->servers.
Length() - 1) this->list_pos++;
833 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
834 this->list_pos = (this->list_pos < this->vscroll->
GetCapacity()) ? 0 : this->list_pos - this->vscroll->
GetCapacity();
838 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
839 this->list_pos =
min(this->list_pos + this->vscroll->
GetCapacity(), (int)this->servers.
Length() - 1);
847 this->list_pos = this->servers.
Length() - 1;
849 default: NOT_REACHED();
852 this->server = this->servers[this->list_pos];
855 this->ScrollToSelectedServer();
862 if (this->server != NULL) {
863 if (keycode == WKC_DELETE) {
865 if (this->server == this->last_joined) this->last_joined = NULL;
867 this->list_pos = SLP_INVALID;
879 this->BuildGUINetworkGameList();
880 this->ScrollToSelectedServer();
887 if (!
StrEmpty(this->name_editbox.text.
buf) && this->name_editbox.text.buf[0] !=
' ') {
898 if (!
StrEmpty(str)) NetworkAddServer(str);
912 Listing NetworkGameWindow::last_sorting = {
false, 5};
926 static NWidgetBase *MakeResizableHeader(
int *biggest_index)
928 *biggest_index = max<int>(*biggest_index,
WID_NG_INFO);
932 static const NWidgetPart _nested_network_game_widgets[] = {
947 SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
953 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
968 SetDataTip(0x0, STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST),
979 SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
1029 _nested_network_game_widgets,
lengthof(_nested_network_game_widgets)
1032 void ShowNetworkGameWindow()
1034 static bool first =
true;
1043 NetworkAddServer(*iter);
1094 size->width += padding.width;
1095 size->height += padding.height;
1113 ShowNetworkGameWindow();
1130 if (!(this->flags &
WF_TIMEOUT) || this->timeout_timer <= 1) {
1131 this->HandleButtonClick(widget);
1134 default: NOT_REACHED();
1169 for (uint i = 0; i <
lengthof(_language_dropdown) - 1; i++) {
1231 for (
const int *widget = raise_widgets; *widget !=
WIDGET_LIST_END; widget++) {
1232 if (this->IsWidgetLowered(*widget)) {
1233 this->RaiseWidget(*widget);
1234 this->SetWidgetDirty(*widget);
1241 if (str == NULL)
return;
1246 int32 value = atoi(str);
1247 this->SetWidgetDirty(this->widget_id);
1248 switch (this->widget_id) {
1249 default: NOT_REACHED();
1260 static const NWidgetPart _nested_network_start_server_window_widgets[] = {
1340 static WindowDesc _network_start_server_window_desc(
1344 _nested_network_start_server_window_widgets,
lengthof(_nested_network_start_server_window_widgets)
1347 static void ShowNetworkStartServerWindow()
1364 this->CreateNestedTree();
1369 CompanyID NetworkLobbyFindCompanyIndex(byte pos)
const 1373 if (!
StrEmpty(this->company_info[i].company_name)) {
1374 if (pos-- == 0)
return i;
1390 size->height = 10 * resize->height;
1412 this->DrawDetails(r);
1435 this->DrawWidgets();
1445 int lock_width = lock_size.width;
1449 int profit_width = lock_size.width;
1452 uint text_left = left + (rtl ? lock_width + profit_width + 4 : 0);
1453 uint text_right = right - (rtl ? 0 : lock_width + profit_width + 4);
1454 uint profit_left = rtl ? left : right - profit_width;
1455 uint lock_left = rtl ? left + profit_width + 2 : right - profit_width - lock_width - 2;
1461 byte company = NetworkLobbyFindCompanyIndex(pos);
1462 bool income =
false;
1463 if (this->company == company) {
1467 DrawString(text_left, text_right, y, this->company_info[company].company_name, TC_BLACK);
1468 if (this->company_info[company].use_password != 0)
DrawSprite(SPR_LOCK, PAL_NONE, lock_left, y + lock_y_offset);
1471 if (this->company_info[company].income >= 0) income =
true;
1472 DrawSprite(income ? SPR_PROFIT_LOT : SPR_PROFIT_NEGATIVE, PAL_NONE, profit_left, y + profit_y_offset);
1475 y += this->resize.step_height;
1480 void DrawDetails(
const Rect &r)
const 1489 int y = r.top + detail_height + 4;
1499 SetDParamStr(0, this->company_info[this->company].company_name);
1503 SetDParam(0, this->company_info[this->company].inaugurated_year);
1507 SetDParam(0, this->company_info[this->company].company_value);
1511 SetDParam(0, this->company_info[this->company].money);
1515 SetDParam(0, this->company_info[this->company].income);
1519 SetDParam(0, this->company_info[this->company].performance);
1523 SetDParam(0, this->company_info[this->company].num_vehicle[NETWORK_VEH_TRAIN]);
1524 SetDParam(1, this->company_info[this->company].num_vehicle[NETWORK_VEH_LORRY]);
1525 SetDParam(2, this->company_info[this->company].num_vehicle[NETWORK_VEH_BUS]);
1526 SetDParam(3, this->company_info[this->company].num_vehicle[NETWORK_VEH_SHIP]);
1527 SetDParam(4, this->company_info[this->company].num_vehicle[NETWORK_VEH_PLANE]);
1531 SetDParam(0, this->company_info[this->company].num_station[NETWORK_VEH_TRAIN]);
1532 SetDParam(1, this->company_info[this->company].num_station[NETWORK_VEH_LORRY]);
1533 SetDParam(2, this->company_info[this->company].num_station[NETWORK_VEH_BUS]);
1534 SetDParam(3, this->company_info[this->company].num_station[NETWORK_VEH_SHIP]);
1535 SetDParam(4, this->company_info[this->company].num_station[NETWORK_VEH_PLANE]);
1539 SetDParamStr(0, this->company_info[this->company].clients);
1547 ShowNetworkGameWindow();
1577 memset(this->company_info, 0,
sizeof(this->company_info));
1588 static const NWidgetPart _nested_network_lobby_window_widgets[] = {
1594 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),
1599 NWidget(
WWT_PANEL, COLOUR_WHITE,
WID_NL_HEADER),
SetMinimalSize(146, 0),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
1600 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),
1605 NWidget(
WWT_PANEL, COLOUR_LIGHT_BLUE,
WID_NL_DETAILS),
SetMinimalSize(232, 0),
SetResize(1, 1),
SetFill(1, 1),
EndContainer(),
1627 static WindowDesc _network_lobby_window_desc(
1631 _nested_network_lobby_window_widgets,
lengthof(_nested_network_lobby_window_widgets)
1657 return (lobby != NULL && company <
MAX_COMPANIES) ? &lobby->company_info[company] : NULL;
1672 static const NWidgetPart _nested_client_list_popup_widgets[] = {
1680 _nested_client_list_popup_widgets,
lengthof(_nested_client_list_popup_widgets)
1724 Point desired_location;
1735 action->
name = name;
1736 action->
proc = proc;
1741 sel_index(0), client_id(client_id)
1743 this->desired_location.x = x;
1744 this->desired_location.y = y;
1749 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
1753 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, &ClientList_SpeakToCompany);
1755 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, &ClientList_SpeakToAll);
1760 this->AddAction(STR_NETWORK_CLIENTLIST_GIVE_MONEY, &ClientList_GiveMoney);
1766 this->AddAction(STR_NETWORK_CLIENTLIST_KICK, &ClientList_Kick);
1767 this->AddAction(STR_NETWORK_CLIENTLIST_BAN, &ClientList_Ban);
1770 this->InitNested(client_id);
1776 return this->desired_location;
1786 d.height *= this->actions.
Length();
1795 int sel = this->sel_index;
1816 if (index == this->sel_index || index >= this->actions.
Length())
return;
1818 this->sel_index = index;
1821 if (index < this->actions.
Length() && _cursor.
pos.y >= this->top) {
1823 if (ci != NULL) this->actions[index].proc(ci);
1843 static const NWidgetPart _nested_client_list_widgets[] = {
1856 _nested_client_list_widgets,
lengthof(_nested_client_list_widgets)
1865 uint server_client_width;
1874 this->InitNested(window_number);
1890 num *= this->line_height;
1921 if (!this->CheckClientListHeight())
return;
1923 this->DrawWidgets();
1931 int icon_offset = (this->line_height - icon_size.height) / 2;
1937 uint type_icon_width = this->server_client_width + this->icon_size.width +
WD_FRAMERECT_LEFT;
1940 uint type_left = rtl ? right - this->server_client_width : left;
1941 uint type_right = rtl ? right : left + this->server_client_width - 1;
1942 uint icon_left = rtl ? right - type_icon_width +
WD_FRAMERECT_LEFT : left + this->server_client_width;
1943 uint name_left = rtl ? left : left + type_icon_width;
1944 uint name_right = rtl ? right - type_icon_width : right;
1950 if (this->selected_item == i++) {
1958 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_SERVER, colour);
1960 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_CLIENT, colour);
1975 if (this->selected_item != -1) {
1978 int client_no = this->selected_item;
1980 if (client_no == 0)
break;
1992 this->selected_item = -1;
2005 if (item == this->selected_item)
return;
2006 this->selected_item = item;
2013 void ShowClientList()
2015 AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
2037 DrawString(r.left + 2, r.right - 2, r.top + 20, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING,
SA_HOR_CENTER);
2038 switch (_network_join_status) {
2039 case NETWORK_JOIN_STATUS_CONNECTING:
case NETWORK_JOIN_STATUS_AUTHORIZING:
2040 case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
2043 case NETWORK_JOIN_STATUS_WAITING:
2048 case NETWORK_JOIN_STATUS_DOWNLOADING:
2050 SetDParam(1, _network_join_bytes_total);
2051 DrawString(r.left + 2, r.right - 2, r.top + 20 +
FONT_HEIGHT_NORMAL, _network_join_bytes_total == 0 ? STR_NETWORK_CONNECTING_DOWNLOADING_1 : STR_NETWORK_CONNECTING_DOWNLOADING_2, TC_FROMSTRING,
SA_HOR_CENTER);
2052 if (_network_join_bytes_total == 0) {
2059 progress = 15 + _network_join_bytes * (100 - 15) / _network_join_bytes_total;
2063 DrawFrameRect(r.left + 20, r.top + 5, (
int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
2074 for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
2097 ShowNetworkGameWindow();
2105 ShowNetworkGameWindow();
2109 switch (this->password_type) {
2112 default: NOT_REACHED();
2117 static const NWidgetPart _nested_network_join_status_window_widgets[] = {
2130 static WindowDesc _network_join_status_window_desc(
2134 _nested_network_join_status_window_widgets,
lengthof(_nested_network_join_status_window_widgets)
2137 void ShowJoinStatusWindow()
2146 if (w == NULL)
return;
2147 w->password_type = npt;
2151 default: NOT_REACHED();
2163 this->InitNested(0);
2165 this->parent = parent;
2200 static const NWidgetPart _nested_network_company_password_window_widgets[] = {
2214 SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
2224 static WindowDesc _network_company_password_window_desc(
2228 _nested_network_company_password_window_widgets,
lengthof(_nested_network_company_password_window_widgets)
2231 void ShowNetworkCompanyPasswordWindow(
Window *parent)
EventState
State of handling an event.
Date start_date
When the game started.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
byte spectators_max
Max spectators allowed on server.
uint16 map_height
Map height.
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.
Send message/notice to all clients (All)
Main handle for clientlist.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
Ban, or kick, everyone joined from the given client's IP.
void RebuildDone()
Notify the sortlist that the rebuild is done.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool CheckClientListHeight()
Finds the amount of clients and set the height correct.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Container for all information known about a client.
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
Horizontally center the text.
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...
bool server_advertise
advertise the server to the masterserver
Point pos
logical mouse position
uint8 lan_internet
search on the LAN or internet for servers
uint16 last_port
port of the last joined server
High level window description.
Client list; Window numbers:
EconomySettings economy
settings to change the economy
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
char server_name[NETWORK_NAME_LENGTH]
name of the server
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
Switch to game intro menu.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
void StartNewGameWithoutGUI(uint seed)
Start a normal game without the GUI.
NetworkGameList * next
Next pointer to make a linked game list.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
GUIs related to networking.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
byte server_lang
Language of the server (we should make a nice table for this)
static int CDECL NGameNameSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by name.
Offset at top to draw the frame rectangular area.
Normal amount of vertical space between two paragraphs of text.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
bool GetState() const
Get the matching state of the current item.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
virtual void OnPaint()
The window must be repainted.
ClientID client_id
Client identifier (same as ClientState->client_id)
Popup for the client list; Window numbers:
bool version_compatible
Can we connect to this server or not? (based on server_revision)
NetworkJoinStatus _network_join_status
The status of joining.
static const int ACTION_CLEAR
Clear editbox.
NetworkGameList * last_joined
the last joined server
static const uint MAX_CLIENTS
How many clients can we have.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Sending and receiving UDP messages.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Client part of the network protocol.
void Clear()
Remove all items from the list.
QueryString filter_editbox
Editbox for filter on servers.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
void Compact()
Compact the list down to the smallest block size boundary.
ServerListPosition list_pos
position of the selected server
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
const T * Begin() const
Get the pointer to the first item (const)
static const uint GENERATE_NEW_SEED
Create a new random seed.
bool give_money
allow giving other companies money
QueryString password_editbox
Password editbox.
Offset at top of a matrix cell.
uint16 map_width
Map width.
Send message/notice to only a certain client (Private)
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
static int CDECL NGameMapSizeSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by map size.
#define lastof(x)
Get the last element of an fixed size array.
The client is spectating.
The client wants a new company.
Simple vector template class.
return success even when the text didn't change
Base core network types and some helper functions to access them.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Structure with information shown in the game list (GUI)
#define CLRBITS(x, y)
Clears several bits in a variable.
virtual void OnMouseOver(Point pt, int widget)
The mouse is currently moving over the window or has just moved outside of the window.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
virtual void OnPaint()
The window must be repainted.
static T max(const T a, const T b)
Returns the maximum of two values.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
const T * End() const
Get the pointer behind the last valid item (const)
void SetListing(Listing l)
Import sort conditions.
char server_name[NETWORK_NAME_LENGTH]
Server name.
bool NeedRebuild() const
Check if a rebuild is needed.
Servers always have this ID.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
void SortNetworkGameList()
Sort the server list.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
bool _left_button_clicked
Is left mouse button clicked?
The password of the company.
T * Append(uint to_add=1)
Append an item and return it.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void ForceRebuild()
Force that a rebuild is needed.
Data structure for an opened window.
The game information that is sent from the server to the clients.
bool _ctrl_pressed
Is Ctrl pressed?
byte companies_max
Max companies allowed on server.
void SetFilterTerm(const char *str)
Set the term to filter on.
byte widget_id
The widget that has the pop-up input menu.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
NetworkSettings network
settings related to the network
void BuildGUINetworkGameList()
(Re)build the GUI network game list (a.k.a.
bool _is_network_server
Does this client wants to be a network-server?
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
NetworkGameList * NetworkGameListAddItem(NetworkAddress address)
Add a new item to the linked gamelist.
CompanyID client_playas
As which company is this client playing (CompanyID)
byte companies_on
How many started companies do we have.
void NetworkUDPSearchGame()
Find all servers.
static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
Show the networklobbywindow with the selected server.
Offset at bottom of a matrix cell.
uint Length() const
Get the number of items in the list.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
virtual void OnResize()
Called after the window got resized.
void NetworkServerKickClient(ClientID client_id)
Kick a single client.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Listing GetListing() const
Export current sort conditions.
virtual void OnTick()
Called once per (game) tick.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
uint8 max_spectators
maximum amount of spectators
byte clients_max
Max clients allowed on server.
Company information stored at the client side.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
bool _left_button_down
Is left mouse button pressed?
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
Draw a single server line.
Data stored about a string that can be modified in the GUI.
virtual void OnPaint()
The window must be repainted.
ClientID _network_own_client_id
Our client identifier.
ClientSettings _settings_client
The current settings for this game.
void NetworkUDPQueryMasterServer()
Request the the server-list from the master server.
Data structure to convert between Date and triplet (year, month, and day).
bool use_password
Is this server passworded?
static int CDECL NGameAllowedSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by joinability.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
char connect_to_ip[NETWORK_HOSTNAME_LENGTH]
default for the "Add server" query
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
First company, same as owner.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
static const StringID _connection_types_dropdown[]
Advertisement options in the start server window.
void ShowGenerateLandscape()
Start with a normal game.
NetworkAddress address
The connection info of the game server.
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
#define FOR_ALL_CLIENT_INFOS(var)
Iterate over all the clients.
byte clients_on
Current count of clients on server.
NetworkGameInfo info
The game information of this server.
char server_revision[NETWORK_REVISION_LENGTH]
The version number the server is using (e.g.: 'r304' or 0.5.0)
NetworkGameList * _network_game_list
Game list of this client.
Offset at bottom to draw the frame rectangular area.
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.
static int CDECL NGameDateSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by current date.
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void NetworkGameListRequery()
Requeries the (game) servers we have not gotten a reply from.
int lock_offset
Left offset for lock icon.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
uint8 server_lang
language of the server
virtual void OnResize()
Called after the window got resized.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static const uint8 PC_BLACK
Black palette colour.
uint32 _network_join_bytes
The number of bytes we already downloaded.
Maximum number of companies.
NetworkGameList * server
Selected server.
The window is a modal child of some other window, meaning the parent is 'inactive'.
uint8 max_companies
maximum amount of companies
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
CompanyID company
Selected company.
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Network status window; Window numbers:
void AddLine(const char *str)
Pass another text line from the current item to the filter.
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
StringList _network_host_list
The servers we know.
int blot_offset
Left offset for green/yellow/red compatibility icon.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
byte map_set
Graphical set.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static const StringID _lan_internet_types_dropdown[]
Advertisement options in the server list.
Date game_date
Current date.
static const uint8 PC_GREY
Grey palette colour.
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
void DrawCompanyIcon(CompanyID cid, int x, int y)
Draw the icon of a company.
The password of the game.
bool online
False if the server did not respond (default status)
char *const buf
buffer in which text is saved
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
Both numeric and alphabetic and spaces and stuff.
static int CDECL NGameYearsSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by the number of days the game is running.
NetworkJoinStatus
Status of the clients during joining.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void SetFilterState(bool state)
Enable or disable the filter.
int flag_offset
Left offset for langauge flag icon.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Handling of the list of games.
TextDirection _current_text_dir
Text direction of the currently selected language.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
static void PopupClientList(ClientID client_id, int x, int y)
Show the popup (action list)
bool CDECL FilterFunction(const T *, F)
Signature of filter function.
uint8 max_clients
maximum amount of clients
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.
ClientID
'Unique' identifier to be given to clients
int CDECL SortFunction(const T *, const T *)
Signature of sort function.
virtual void OnTimeout()
Called when this window's timeout has been reached.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Network window; Window numbers:
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
static void NetworkUDPQueryServer(NetworkAddress *address, bool needs_mutex, bool manually)
Helper function doing the actual work for querying the server.
bool _network_server
network-server is active
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Data structure describing how to show the list (what sort direction and criteria).
uint16 GetPort() const
Get the port.
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
uint32 _network_join_bytes_total
The total number of bytes to download.
Offset at right to draw the frame rectangular area.
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
Company password query; Window numbers:
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) ...
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
QueryString name_editbox
Client name editbox.
bool IsDescSortOrder() const
Check if the sort order is descending.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
NetworkGameList * server
selected server
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
NetworkPasswordType
The type of password we're asking for.
The passed event is handled.
void ScrollToSelectedServer()
Scroll the list up or down to the currently selected server.
Text is written right-to-left by default.
void ClientList_Action_Proc(const NetworkClientInfo *ci)
Prototype for ClientList actions.
Owner
Enum for all companies/owners.
QueryString name_editbox
Server name editbox.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Find a place automatically.
GUIGameServerList servers
list with game servers.
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
uint8 _network_join_waiting
The number of clients waiting in front of us.
GRFConfig * grfconfig
List of NewGRF files used.
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
uint32 WChar
Type for wide characters, i.e.
Scrollbar * vscroll
vertical scrollbar of the list of servers
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Window white border counter bit mask.
Send message/notice to everyone playing the same company (Team)
Dimensions (a width and height) of a rectangle in 2D.
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
void UpdateListPos()
Set this->list_pos to match this->server.
static int CDECL NGameClientSorter(NetworkGameList *const *a, NetworkGameList *const *b)
Sort servers by the amount of clients online on a server.
void GetAddressAsString(char *buffer, const char *last, bool with_family=true)
Get the address as a string, e.g.
byte spectators_on
How many spectators do we have?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
static const SpriteID SPR_FLAGS_BASE
Flags sprites (in same order as enum NetworkLanguage)
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-...
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
uint8 SortType() const
Get the sorttype of the list.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.