12 #include "../stdafx.h" 13 #include "../strings_func.h" 14 #include "../date_func.h" 24 #include "../window_func.h" 25 #include "../gfx_func.h" 26 #include "../widgets/dropdown_func.h" 27 #include "../querystring_gui.h" 28 #include "../sortlist_type.h" 29 #include "../company_func.h" 30 #include "../core/geometry_func.hpp" 31 #include "../genworld.h" 32 #include "../map_type.h" 33 #include "../guitimer_func.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 std::vector<StringID> _language_dropdown;
68 void SortNetworkLanguages()
71 if (_language_dropdown.empty()) {
72 for (
int i = 0; i < NETLANG_COUNT; i++) _language_dropdown.emplace_back(STR_NETWORK_LANG_ANY + i);
77 std::sort(_language_dropdown.begin() + 1, _language_dropdown.end() - 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 !=
nullptr; 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 !=
nullptr; 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 !=
nullptr) {
176 if (this->visible[i]) {
181 child_wid = rtl ? child_wid->
prev : child_wid->
next;
189 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
190 if (!this->visible[i++])
continue;
201 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
202 if (!this->visible[i++])
continue;
204 if (nwid !=
nullptr)
return nwid;
253 this->servers.clear();
256 this->servers.push_back(ngl);
270 this->servers.shrink_to_fit();
272 this->vscroll->
SetCount((
int)this->servers.size());
275 this->servers.
Sort();
276 this->UpdateListPos();
297 if (r == 0)
return NGameNameSorter(a, b);
309 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
316 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
323 return (r != 0) ? r < 0: NGameDateSorter(a, b);
342 if (r == 0)
return NGameClientSorter(a, b);
350 if (this->servers.
Sort()) this->UpdateListPos();
356 this->list_pos = SLP_INVALID;
357 for (uint i = 0; i != this->servers.size(); i++) {
358 if (this->servers[i] == this->server) {
367 assert(item !=
nullptr);
368 assert((*item) !=
nullptr);
371 sf.
AddLine((*item)->info.server_name);
387 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);
391 int icon_y_offset = (this->resize.step_height -
GetSpriteSize(SPR_BLOT).height) / 2;
431 SetDParam(0, ymd_cur.year - ymd_start.year);
455 if (this->list_pos == SLP_INVALID)
return;
462 this->list_pos = SLP_INVALID;
463 this->server =
nullptr;
465 this->lock_offset = 5;
466 this->blot_offset = this->lock_offset + 3 +
GetSpriteSize(SPR_LOCK).width;
467 this->flag_offset = this->blot_offset + 2 +
GetSpriteSize(SPR_BLOT).width;
469 this->CreateNestedTree();
481 this->server = this->last_joined;
494 this->last_sorting = this->servers.
GetListing();
511 size->width += padding.width;
512 size->height += padding.height;
517 size->height = 10 * resize->height;
525 size->width = NWidgetScrollbar::GetVerticalDimension().width;
571 this->DrawServerLine(ngl, y, ngl == this->server);
572 y += this->resize.step_height;
579 if (this->last_joined !=
nullptr) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
583 this->DrawDetails(r);
601 this->BuildGUINetworkGameList();
604 this->SortNetworkGameList();
611 this->SetWidgetDisabledState(
WID_NG_JOIN, sel ==
nullptr ||
623 void DrawDetails(
const Rect &r)
const 631 if (sel ==
nullptr) {
633 }
else if (!sel->
online) {
643 uint16 y = r.top + detail_height + 4;
713 if (this->list_pos != SLP_INVALID) this->list_pos = (ServerListPosition)this->servers.size() - this->list_pos - 1;
717 this->SortNetworkGameList();
719 this->ScrollToSelectedServer();
725 this->server = (id_v < this->servers.size()) ? this->servers[id_v] :
nullptr;
726 this->list_pos = (server ==
nullptr) ? SLP_INVALID : id_v;
735 if (this->last_joined !=
nullptr) {
736 this->server = this->last_joined;
739 this->UpdateListPos();
740 this->ScrollToSelectedServer();
760 STR_NETWORK_SERVER_LIST_ENTER_IP,
766 ShowNetworkStartServerWindow();
770 if (this->server !=
nullptr) {
821 if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
822 if (this->servers.size() == 0)
return ES_HANDLED;
826 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
827 if (this->list_pos > 0) this->list_pos--;
831 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
832 if (this->list_pos < this->servers.size() - 1) this->list_pos++;
836 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
837 this->list_pos = (this->list_pos < this->vscroll->
GetCapacity()) ? 0 : this->list_pos - this->vscroll->
GetCapacity();
841 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
842 this->list_pos =
min(this->list_pos + this->vscroll->
GetCapacity(), (int)this->servers.size() - 1);
850 this->list_pos = (ServerListPosition)this->servers.size() - 1;
852 default: NOT_REACHED();
855 this->server = this->servers[this->list_pos];
858 this->ScrollToSelectedServer();
865 if (this->server !=
nullptr) {
866 if (keycode == WKC_DELETE) {
868 if (this->server == this->last_joined) this->last_joined =
nullptr;
869 this->server =
nullptr;
870 this->list_pos = SLP_INVALID;
882 this->BuildGUINetworkGameList();
883 this->ScrollToSelectedServer();
890 if (!
StrEmpty(this->name_editbox.text.
buf) && this->name_editbox.text.buf[0] !=
' ') {
901 if (!
StrEmpty(str)) NetworkAddServer(str);
911 if (!this->requery_timer.
Elapsed(delta_ms))
return;
918 Listing NetworkGameWindow::last_sorting = {
false, 5};
932 static NWidgetBase *MakeResizableHeader(
int *biggest_index)
934 *biggest_index = max<int>(*biggest_index,
WID_NG_INFO);
938 static const NWidgetPart _nested_network_game_widgets[] = {
953 SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
959 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
974 SetDataTip(0x0, STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST),
985 SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
1035 _nested_network_game_widgets,
lengthof(_nested_network_game_widgets)
1038 void ShowNetworkGameWindow()
1040 static bool first =
true;
1049 NetworkAddServer(iter.c_str());
1100 size->width += padding.width;
1101 size->height += padding.height;
1119 ShowNetworkGameWindow();
1136 if (!(this->flags &
WF_TIMEOUT) || this->timeout_timer <= 1) {
1137 this->HandleButtonClick(widget);
1140 default: NOT_REACHED();
1175 for (uint i = 0; i < _language_dropdown.size() - 1; i++) {
1237 for (
const int *widget = raise_widgets; *widget !=
WIDGET_LIST_END; widget++) {
1238 if (this->IsWidgetLowered(*widget)) {
1239 this->RaiseWidget(*widget);
1240 this->SetWidgetDirty(*widget);
1247 if (str ==
nullptr)
return;
1252 int32 value = atoi(str);
1253 this->SetWidgetDirty(this->widget_id);
1254 switch (this->widget_id) {
1255 default: NOT_REACHED();
1266 static const NWidgetPart _nested_network_start_server_window_widgets[] = {
1346 static WindowDesc _network_start_server_window_desc(
1350 _nested_network_start_server_window_widgets,
lengthof(_nested_network_start_server_window_widgets)
1353 static void ShowNetworkStartServerWindow()
1370 this->CreateNestedTree();
1375 CompanyID NetworkLobbyFindCompanyIndex(byte pos)
const 1379 if (!
StrEmpty(this->company_info[i].company_name)) {
1380 if (pos-- == 0)
return i;
1396 size->height = 10 * resize->height;
1418 this->DrawDetails(r);
1441 this->DrawWidgets();
1451 int lock_width = lock_size.width;
1455 int profit_width = lock_size.width;
1458 uint text_left = left + (rtl ? lock_width + profit_width + 4 : 0);
1459 uint text_right = right - (rtl ? 0 : lock_width + profit_width + 4);
1460 uint profit_left = rtl ? left : right - profit_width;
1461 uint lock_left = rtl ? left + profit_width + 2 : right - profit_width - lock_width - 2;
1467 byte company = NetworkLobbyFindCompanyIndex(pos);
1468 bool income =
false;
1469 if (this->company == company) {
1473 DrawString(text_left, text_right, y, this->company_info[company].company_name, TC_BLACK);
1474 if (this->company_info[company].use_password != 0)
DrawSprite(SPR_LOCK, PAL_NONE, lock_left, y + lock_y_offset);
1477 if (this->company_info[company].income >= 0) income =
true;
1478 DrawSprite(income ? SPR_PROFIT_LOT : SPR_PROFIT_NEGATIVE, PAL_NONE, profit_left, y + profit_y_offset);
1481 y += this->resize.step_height;
1486 void DrawDetails(
const Rect &r)
const 1495 int y = r.top + detail_height + 4;
1505 SetDParamStr(0, this->company_info[this->company].company_name);
1509 SetDParam(0, this->company_info[this->company].inaugurated_year);
1513 SetDParam(0, this->company_info[this->company].company_value);
1517 SetDParam(0, this->company_info[this->company].money);
1521 SetDParam(0, this->company_info[this->company].income);
1525 SetDParam(0, this->company_info[this->company].performance);
1529 SetDParam(0, this->company_info[this->company].num_vehicle[NETWORK_VEH_TRAIN]);
1530 SetDParam(1, this->company_info[this->company].num_vehicle[NETWORK_VEH_LORRY]);
1531 SetDParam(2, this->company_info[this->company].num_vehicle[NETWORK_VEH_BUS]);
1532 SetDParam(3, this->company_info[this->company].num_vehicle[NETWORK_VEH_SHIP]);
1533 SetDParam(4, this->company_info[this->company].num_vehicle[NETWORK_VEH_PLANE]);
1537 SetDParam(0, this->company_info[this->company].num_station[NETWORK_VEH_TRAIN]);
1538 SetDParam(1, this->company_info[this->company].num_station[NETWORK_VEH_LORRY]);
1539 SetDParam(2, this->company_info[this->company].num_station[NETWORK_VEH_BUS]);
1540 SetDParam(3, this->company_info[this->company].num_station[NETWORK_VEH_SHIP]);
1541 SetDParam(4, this->company_info[this->company].num_station[NETWORK_VEH_PLANE]);
1545 SetDParamStr(0, this->company_info[this->company].clients);
1553 ShowNetworkGameWindow();
1583 memset(this->company_info, 0,
sizeof(this->company_info));
1594 static const NWidgetPart _nested_network_lobby_window_widgets[] = {
1600 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),
1605 NWidget(
WWT_PANEL, COLOUR_WHITE,
WID_NL_HEADER),
SetMinimalSize(146, 0),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
1606 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),
1611 NWidget(
WWT_PANEL, COLOUR_LIGHT_BLUE,
WID_NL_DETAILS),
SetMinimalSize(232, 0),
SetResize(1, 1),
SetFill(1, 1),
EndContainer(),
1633 static WindowDesc _network_lobby_window_desc(
1637 _nested_network_lobby_window_widgets,
lengthof(_nested_network_lobby_window_widgets)
1663 return (lobby !=
nullptr && company <
MAX_COMPANIES) ? &lobby->company_info[company] :
nullptr;
1678 static const NWidgetPart _nested_client_list_popup_widgets[] = {
1686 _nested_client_list_popup_widgets,
lengthof(_nested_client_list_popup_widgets)
1730 Point desired_location;
1740 this->actions.push_back({name, proc});
1745 sel_index(0), client_id(client_id)
1747 this->desired_location.x = x;
1748 this->desired_location.y = y;
1753 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
1757 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, &ClientList_SpeakToCompany);
1759 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, &ClientList_SpeakToAll);
1764 this->AddAction(STR_NETWORK_CLIENTLIST_GIVE_MONEY, &ClientList_GiveMoney);
1770 this->AddAction(STR_NETWORK_CLIENTLIST_KICK, &ClientList_Kick);
1771 this->AddAction(STR_NETWORK_CLIENTLIST_BAN, &ClientList_Ban);
1774 this->InitNested(client_id);
1780 return this->desired_location;
1790 d.height *= (uint)this->actions.size();
1799 int sel = this->sel_index;
1821 if (index == this->sel_index || index >= this->actions.size())
return;
1823 this->sel_index = index;
1826 if (index < this->actions.size() && _cursor.
pos.y >= this->top) {
1828 if (ci !=
nullptr) this->actions[index].proc(ci);
1848 static const NWidgetPart _nested_client_list_widgets[] = {
1861 _nested_client_list_widgets,
lengthof(_nested_client_list_widgets)
1870 uint server_client_width;
1879 this->InitNested(window_number);
1895 num *= this->line_height;
1926 if (!this->CheckClientListHeight())
return;
1928 this->DrawWidgets();
1936 int icon_offset = (this->line_height - icon_size.height) / 2;
1942 uint type_icon_width = this->server_client_width + this->icon_size.width +
WD_FRAMERECT_LEFT;
1945 uint type_left = rtl ? right - this->server_client_width : left;
1946 uint type_right = rtl ? right : left + this->server_client_width - 1;
1947 uint icon_left = rtl ? right - type_icon_width +
WD_FRAMERECT_LEFT : left + this->server_client_width;
1948 uint name_left = rtl ? left : left + type_icon_width;
1949 uint name_right = rtl ? right - type_icon_width : right;
1955 if (this->selected_item == i++) {
1963 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_SERVER, colour);
1965 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_CLIENT, colour);
1980 if (this->selected_item != -1) {
1983 int client_no = this->selected_item;
1985 if (client_no == 0)
break;
1997 this->selected_item = -1;
2010 if (item == this->selected_item)
return;
2011 this->selected_item = item;
2018 void ShowClientList()
2020 AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
2042 DrawString(r.left + 2, r.right - 2, r.top + 20, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING,
SA_HOR_CENTER);
2043 switch (_network_join_status) {
2044 case NETWORK_JOIN_STATUS_CONNECTING:
case NETWORK_JOIN_STATUS_AUTHORIZING:
2045 case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
2048 case NETWORK_JOIN_STATUS_WAITING:
2053 case NETWORK_JOIN_STATUS_DOWNLOADING:
2055 SetDParam(1, _network_join_bytes_total);
2056 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);
2057 if (_network_join_bytes_total == 0) {
2064 progress = 15 + _network_join_bytes * (100 - 15) / _network_join_bytes_total;
2068 DrawFrameRect(r.left + 20, r.top + 5, (
int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
2079 for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
2102 ShowNetworkGameWindow();
2110 ShowNetworkGameWindow();
2114 switch (this->password_type) {
2117 default: NOT_REACHED();
2122 static const NWidgetPart _nested_network_join_status_window_widgets[] = {
2135 static WindowDesc _network_join_status_window_desc(
2139 _nested_network_join_status_window_widgets,
lengthof(_nested_network_join_status_window_widgets)
2142 void ShowJoinStatusWindow()
2151 if (w ==
nullptr)
return;
2152 w->password_type = npt;
2156 default: NOT_REACHED();
2169 this->InitNested(0);
2170 this->UpdateWarningStringSize();
2172 this->parent = parent;
2179 void UpdateWarningStringSize()
2181 assert(this->nested_root->smallest_x > 0);
2183 this->warning_size.height =
GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width);
2192 *size = this->warning_size;
2202 STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING,
SA_CENTER);
2233 static const NWidgetPart _nested_network_company_password_window_widgets[] = {
2247 SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
2258 static WindowDesc _network_company_password_window_desc(
2262 _nested_network_company_password_window_widgets,
lengthof(_nested_network_company_password_window_widgets)
2265 void ShowNetworkCompanyPasswordWindow(
Window *parent)
EventState
State of handling an event.
Date start_date
When the game started.
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.
byte spectators_max
Max spectators allowed on server.
static bool NGameClientSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the amount of clients online on a 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.
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.
void OnPaint() override
The window must be repainted.
Container for all information known about a client.
Horizontally center the text.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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
void OnPaint() override
The window must be repainted.
uint16 last_port
port of the last joined server
High level window description.
int CompareTo(NetworkAddress &address)
Compare the address of this class with the address of another.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Client list; Window numbers:
EconomySettings economy
settings to change the economy
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.
NetworkGameList * next
Next pointer to make a linked game list.
GUIs related to networking.
void OnResize() override
Called after the window got resized.
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)
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.
bool Elapsed(uint delta)
Test if a timer has elapsed.
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.
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)
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 OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
NetworkJoinStatus _network_join_status
The status of joining.
The client wants a new 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 int ACTION_CLEAR
Clear editbox.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
NetworkGameList * last_joined
the last joined server
static const uint MAX_CLIENTS
How many clients can we have.
Sending and receiving UDP messages.
Client part of the network protocol.
QueryString filter_editbox
Editbox for filter on servers.
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
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...
bool give_money
allow giving other companies money
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
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...
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.
#define lastof(x)
Get the last element of an fixed size array.
return success even when the text didn't change
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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.
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
Query a specific server.
ClientID
'Unique' identifier to be given to clients
static T max(const T a, const T b)
Returns the maximum of two values.
void SetListing(Listing l)
Import sort conditions.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
char server_name[NETWORK_NAME_LENGTH]
Server name.
bool NeedRebuild() const
Check if a rebuild is needed.
void SortNetworkGameList()
Sort the server list.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
bool _left_button_clicked
Is left mouse button clicked?
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.
The password of the company.
void ForceRebuild()
Force that a rebuild is needed.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Data structure for an opened window.
The game information that is sent from the server to the clients.
bool _ctrl_pressed
Is Ctrl pressed?
static bool NGameNameSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by name.
byte companies_max
Max companies allowed on server.
void SetFilterTerm(const char *str)
Set the term to filter on.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
Bottom offset of the text of the frame.
byte widget_id
The widget that has the pop-up input menu.
void OnResize() override
Called after the window got resized.
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?
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.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
void NetworkServerKickClient(ClientID client_id)
Kick a single client.
The client is spectating.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Listing GetListing() const
Export current sort conditions.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
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.
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.
Center both horizontally and vertically.
Data structure to convert between Date and triplet (year, month, and day).
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
bool use_password
Is this server passworded?
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
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
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
void OnPaint() override
The window must be repainted.
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.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
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.
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
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 NetworkGameListRequery()
Requeries the (game) servers we have not gotten a reply from.
Right offset of the text of the frame.
int lock_offset
Left offset for lock icon.
#define lengthof(x)
Return the length of an fixed size array.
static bool NGameDateSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by current date.
static T min(const T a, const T b)
Returns the minimum of two values.
uint8 server_lang
language of the server
Top offset of the text of the frame.
Left offset of the text of the frame.
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.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
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.
static bool NGameYearsSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the number of days the game is running.
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.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
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.
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.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
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 language flag icon.
GUITimer requery_timer
Timer for network requery.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Handling of the list of games.
First company, same as owner.
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)
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
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.
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.
Network window; Window numbers:
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Maximum number of companies.
static bool NGameMapSizeSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by map size.
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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.
Dimension warning_size
How much space to use for the warning text.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Data structure describing how to show the list (what sort direction and criteria).
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint16 GetPort() const
Get the port.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
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) ...
static bool NGameAllowedSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by joinability.
QueryString name_editbox
Client name editbox.
bool IsDescSortOrder() const
Check if the sort order is descending.
Servers always have this ID.
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.
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.
password entry box, show warning about password security
bool SortFunction(const T &, const T &)
Signature of sort function.
GRFConfig * grfconfig
List of NewGRF files used.
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)
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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.
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.
void OnTimeout() override
Called when this window's timeout has been reached.
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-...
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.
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.
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
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.
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.