OpenTTD Source: src/network/network_gui.cpp Source File

OpenTTD Source 12.2

network_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../date_func.h"
13 #include "../fios.h"
14 #include "network_client.h"
15 #include "network_gui.h"
16 #include "network_gamelist.h"
17 #include "network.h"
18 #include "network_base.h"
19 #include "network_content.h"
20 #include "network_server.h"
21 #include "network_coordinator.h"
22 #include "../gui.h"
23 #include "network_udp.h"
24 #include "../window_func.h"
25 #include "../gfx_func.h"
26 #include "../widgets/dropdown_type.h"
27 #include "../widgets/dropdown_func.h"
28 #include "../querystring_gui.h"
29 #include "../sortlist_type.h"
30 #include "../company_func.h"
31 #include "../command_func.h"
32 #include "../core/geometry_func.hpp"
33 #include "../genworld.h"
34 #include "../map_type.h"
35 #include "../guitimer_func.h"
36 #include "../zoom_func.h"
37 #include "../sprite.h"
38 #include "../settings_internal.h"
39
40 #include "../widgets/network_widget.h"
41
42 #include "table/strings.h"
43 #include "../table/sprites.h"
44
45 #include "../stringfilter_type.h"
46
47 #ifdef __EMSCRIPTEN__
48 # include <emscripten.h>
49 #endif
50
51 #include <map>
52
53 #include "../safeguards.h"
54
55 static void ShowNetworkStartServerWindow();
56
57 static const int NETWORK_LIST_REFRESH_DELAY = 30;
58
59 static ClientID _admin_client_id = INVALID_CLIENT_ID;
60 static CompanyID _admin_company_id = INVALID_COMPANY;
61
66 void UpdateNetworkGameWindow()
67 {
68 InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME, 0);
69 }
70
71 static DropDownList BuildVisibilityDropDownList()
72 {
73 DropDownList list;
74
75 list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_LOCAL, SERVER_GAME_TYPE_LOCAL, false));
76 list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY, SERVER_GAME_TYPE_INVITE_ONLY, false));
77 list.emplace_back(new DropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_PUBLIC, SERVER_GAME_TYPE_PUBLIC, false));
78
79 return list;
80 }
81
82 typedef GUIList<NetworkGameList*, StringFilter&> GUIGameServerList;
83 typedef int ServerListPosition;
84 static const ServerListPosition SLP_INVALID = -1;
85
87 class NWidgetServerListHeader : public NWidgetContainer {
88 static const uint MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER = 150;
89 bool visible[6];
90 public:
91 NWidgetServerListHeader() : NWidgetContainer(NWID_HORIZONTAL)
92 {
93 NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NAME, STR_NETWORK_SERVER_LIST_GAME_NAME, STR_NETWORK_SERVER_LIST_GAME_NAME_TOOLTIP);
94 leaf->SetResize(1, 0);
95 leaf->SetFill(1, 0);
96 this->Add(leaf);
97
98 this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_CLIENTS, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION_TOOLTIP));
99 this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_MAPSIZE, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION_TOOLTIP));
100 this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_DATE, STR_NETWORK_SERVER_LIST_DATE_CAPTION, STR_NETWORK_SERVER_LIST_DATE_CAPTION_TOOLTIP));
101 this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_YEARS, STR_NETWORK_SERVER_LIST_YEARS_CAPTION, STR_NETWORK_SERVER_LIST_YEARS_CAPTION_TOOLTIP));
102
103 leaf = new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_INFO, STR_EMPTY, STR_NETWORK_SERVER_LIST_INFO_ICONS_TOOLTIP);
104 leaf->SetMinimalSize(14 + GetSpriteSize(SPR_LOCK, nullptr, ZOOM_LVL_OUT_4X).width
105 + GetSpriteSize(SPR_BLOT, nullptr, ZOOM_LVL_OUT_4X).width
106 + GetSpriteSize(SPR_FLAGS_BASE, nullptr, ZOOM_LVL_OUT_4X).width, 12);
107 leaf->SetFill(0, 1);
108 this->Add(leaf);
109
110 /* First and last are always visible, the rest is implicitly zeroed */
111 this->visible[0] = true;
112 *lastof(this->visible) = true;
113 }
114
115 void SetupSmallestSize(Window *w, bool init_array) override
116 {
117 /* Oh yeah, we ought to be findable! */
118 w->nested_array[WID_NG_HEADER] = this;
119
120 this->smallest_y = 0; // Biggest child.
121 this->fill_x = 1;
122 this->fill_y = 0;
123 this->resize_x = 1; // We only resize in this direction
124 this->resize_y = 0; // We never resize in this direction
125
126 /* First initialise some variables... */
127 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
128 child_wid->SetupSmallestSize(w, init_array);
129 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
130 }
131
132 /* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
133 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
134 child_wid->current_x = child_wid->smallest_x;
135 child_wid->current_y = this->smallest_y;
136 }
137
138 this->smallest_x = this->head->smallest_x + this->tail->smallest_x; // First and last are always shown, rest not
139 }
140
141 void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
142 {
143 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
144
145 this->pos_x = x;
146 this->pos_y = y;
147 this->current_x = given_width;
148 this->current_y = given_height;
149
150 given_width -= this->tail->smallest_x;
151 NWidgetBase *child_wid = this->head->next;
152 /* The first and last widget are always visible, determine which other should be visible */
153 for (uint i = 1; i < lengthof(this->visible) - 1; i++) {
154 if (given_width > MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER + child_wid->smallest_x && this->visible[i - 1]) {
155 this->visible[i] = true;
156 given_width -= child_wid->smallest_x;
157 } else {
158 this->visible[i] = false;
159 }
160 child_wid = child_wid->next;
161 }
162
163 /* All remaining space goes to the first (name) widget */
164 this->head->current_x = given_width;
165
166 /* Now assign the widgets to their rightful place */
167 uint position = 0; // Place to put next child relative to origin of the container.
168 uint i = rtl ? lengthof(this->visible) - 1 : 0;
169 child_wid = rtl ? this->tail : this->head;
170 while (child_wid != nullptr) {
171 if (this->visible[i]) {
172 child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
173 position += child_wid->current_x;
174 }
175
176 child_wid = rtl ? child_wid->prev : child_wid->next;
177 i += rtl ? -1 : 1;
178 }
179 }
180
181 void Draw(const Window *w) override
182 {
183 int i = 0;
184 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
185 if (!this->visible[i++]) continue;
186
187 child_wid->Draw(w);
188 }
189 }
190
191 NWidgetCore *GetWidgetFromPos(int x, int y) override
192 {
193 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
194
195 int i = 0;
196 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
197 if (!this->visible[i++]) continue;
198 NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
199 if (nwid != nullptr) return nwid;
200 }
201 return nullptr;
202 }
203
209 bool IsWidgetVisible(NetworkGameWidgets widget) const
210 {
211 assert((uint)(widget - WID_NG_NAME) < lengthof(this->visible));
212 return this->visible[widget - WID_NG_NAME];
213 }
214 };
215
216 class NetworkGameWindow : public Window {
217 protected:
218 /* Runtime saved values */
219 static Listing last_sorting;
220
221 /* Constants for sorting servers */
222 static GUIGameServerList::SortFunction * const sorter_funcs[];
223 static GUIGameServerList::FilterFunction * const filter_funcs[];
224
225 NetworkGameList *server;
226 NetworkGameList *last_joined;
227 GUIGameServerList servers;
228 ServerListPosition list_pos;
229 Scrollbar *vscroll;
230 QueryString name_editbox;
231 QueryString filter_editbox;
232 GUITimer requery_timer;
233 bool searched_internet = false;
234
235 int lock_offset;
236 int blot_offset;
237 int flag_offset;
238
244 void BuildGUINetworkGameList()
245 {
246 if (!this->servers.NeedRebuild()) return;
247
248 /* Create temporary array of games to use for listing */
249 this->servers.clear();
250
251 bool found_current_server = false;
252 bool found_last_joined = false;
253 for (NetworkGameList *ngl = _network_game_list; ngl != nullptr; ngl = ngl->next) {
254 this->servers.push_back(ngl);
255 if (ngl == this->server) {
256 found_current_server = true;
257 }
258 if (ngl == this->last_joined) {
259 found_last_joined = true;
260 }
261 }
262 /* A refresh can cause the current server to be delete; so unselect. */
263 if (!found_last_joined) {
264 this->last_joined = nullptr;
265 }
266 if (!found_current_server) {
267 this->server = nullptr;
268 this->list_pos = SLP_INVALID;
269 }
270
271 /* Apply the filter condition immediately, if a search string has been provided. */
272 StringFilter sf;
273 sf.SetFilterTerm(this->filter_editbox.text.buf);
274
275 if (!sf.IsEmpty()) {
276 this->servers.SetFilterState(true);
277 this->servers.Filter(sf);
278 } else {
279 this->servers.SetFilterState(false);
280 }
281
282 this->servers.shrink_to_fit();
283 this->servers.RebuildDone();
284 this->vscroll->SetCount((int)this->servers.size());
285
286 /* Sort the list of network games as requested. */
287 this->servers.Sort();
288 this->UpdateListPos();
289 }
290
292 static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b)
293 {
294 int r = strnatcmp(a->info.server_name.c_str(), b->info.server_name.c_str(), true); // Sort by name (natural sorting).
295 if (r == 0) r = a->connection_string.compare(b->connection_string);
296
297 return r < 0;
298 }
299
305 static bool NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b)
306 {
307 /* Reverse as per default we are interested in most-clients first */
308 int r = a->info.clients_on - b->info.clients_on;
309
310 if (r == 0) r = a->info.clients_max - b->info.clients_max;
311 if (r == 0) return NGameNameSorter(a, b);
312
313 return r < 0;
314 }
315
317 static bool NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b)
318 {
319 /* Sort by the area of the map. */
320 int r = (a->info.map_height) * (a->info.map_width) - (b->info.map_height) * (b->info.map_width);
321
322 if (r == 0) r = a->info.map_width - b->info.map_width;
323 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
324 }
325
327 static bool NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b)
328 {
329 int r = a->info.game_date - b->info.game_date;
330 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
331 }
332
334 static bool NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b)
335 {
336 int r = a->info.game_date - a->info.start_date - b->info.game_date + b->info.start_date;
337 return (r != 0) ? r < 0: NGameDateSorter(a, b);
338 }
339
344 static bool NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b)
345 {
346 /* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
347 int r = a->info.server_revision.empty() - b->info.server_revision.empty();
348
349 /* Reverse default as we are interested in version-compatible clients first */
350 if (r == 0) r = b->info.version_compatible - a->info.version_compatible;
351 /* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
352 if (r == 0) r = b->info.compatible - a->info.compatible;
353 /* Passworded servers should be below unpassworded servers */
354 if (r == 0) r = a->info.use_password - b->info.use_password;
355
356 /* Finally sort on the number of clients of the server in reverse order. */
357 return (r != 0) ? r < 0 : NGameClientSorter(b, a);
358 }
359
361 void SortNetworkGameList()
362 {
363 if (this->servers.Sort()) this->UpdateListPos();
364 }
365
367 void UpdateListPos()
368 {
369 this->list_pos = SLP_INVALID;
370 for (uint i = 0; i != this->servers.size(); i++) {
371 if (this->servers[i] == this->server) {
372 this->list_pos = i;
373 break;
374 }
375 }
376 }
377
378 static bool CDECL NGameSearchFilter(NetworkGameList * const *item, StringFilter &sf)
379 {
380 assert(item != nullptr);
381 assert((*item) != nullptr);
382
383 sf.ResetState();
384 sf.AddLine((*item)->info.server_name.c_str());
385 return sf.GetState();
386 }
387
394 void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
395 {
396 const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(WID_NG_NAME);
397 const NWidgetBase *nwi_info = this->GetWidget<NWidgetBase>(WID_NG_INFO);
398
399 /* show highlighted item with a different colour */
400 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);
401
402 /* offsets to vertically centre text and icons */
403 int text_y_offset = (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2 + 1;
404 int icon_y_offset = (this->resize.step_height - GetSpriteSize(SPR_BLOT).height) / 2;
405 int lock_y_offset = (this->resize.step_height - GetSpriteSize(SPR_LOCK).height) / 2;
406
407 DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + text_y_offset, cur_item->info.server_name, TC_BLACK);
408
409 /* only draw details if the server is online */
410 if (cur_item->status == NGLS_ONLINE) {
411 const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(WID_NG_HEADER);
412
413 if (nwi_header->IsWidgetVisible(WID_NG_CLIENTS)) {
414 const NWidgetBase *nwi_clients = this->GetWidget<NWidgetBase>(WID_NG_CLIENTS);
415 SetDParam(0, cur_item->info.clients_on);
416 SetDParam(1, cur_item->info.clients_max);
417 SetDParam(2, cur_item->info.companies_on);
418 SetDParam(3, cur_item->info.companies_max);
419 DrawString(nwi_clients->pos_x, nwi_clients->pos_x + nwi_clients->current_x - 1, y + text_y_offset, STR_NETWORK_SERVER_LIST_GENERAL_ONLINE, TC_FROMSTRING, SA_HOR_CENTER);
420 }
421
422 if (nwi_header->IsWidgetVisible(WID_NG_MAPSIZE)) {
423 /* map size */
424 const NWidgetBase *nwi_mapsize = this->GetWidget<NWidgetBase>(WID_NG_MAPSIZE);
425 SetDParam(0, cur_item->info.map_width);
426 SetDParam(1, cur_item->info.map_height);
427 DrawString(nwi_mapsize->pos_x, nwi_mapsize->pos_x + nwi_mapsize->current_x - 1, y + text_y_offset, STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, TC_FROMSTRING, SA_HOR_CENTER);
428 }
429
430 if (nwi_header->IsWidgetVisible(WID_NG_DATE)) {
431 /* current date */
432 const NWidgetBase *nwi_date = this->GetWidget<NWidgetBase>(WID_NG_DATE);
433 YearMonthDay ymd;
434 ConvertDateToYMD(cur_item->info.game_date, &ymd);
435 SetDParam(0, ymd.year);
436 DrawString(nwi_date->pos_x, nwi_date->pos_x + nwi_date->current_x - 1, y + text_y_offset, STR_JUST_INT, TC_BLACK, SA_HOR_CENTER);
437 }
438
439 if (nwi_header->IsWidgetVisible(WID_NG_YEARS)) {
440 /* number of years the game is running */
441 const NWidgetBase *nwi_years = this->GetWidget<NWidgetBase>(WID_NG_YEARS);
442 YearMonthDay ymd_cur, ymd_start;
443 ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
444 ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
445 SetDParam(0, ymd_cur.year - ymd_start.year);
446 DrawString(nwi_years->pos_x, nwi_years->pos_x + nwi_years->current_x - 1, y + text_y_offset, STR_JUST_INT, TC_BLACK, SA_HOR_CENTER);
447 }
448
449 /* draw a lock if the server is password protected */
450 if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, nwi_info->pos_x + this->lock_offset, y + lock_y_offset);
451
452 /* draw red or green icon, depending on compatibility with server */
453 DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), nwi_info->pos_x + this->blot_offset, y + icon_y_offset + 1);
454 }
455 }
456
464 void ScrollToSelectedServer()
465 {
466 if (this->list_pos == SLP_INVALID) return; // no server selected
467 this->vscroll->ScrollTowards(this->list_pos);
468 }
469
470 public:
471 NetworkGameWindow(WindowDesc *desc) : Window(desc), name_editbox(NETWORK_CLIENT_NAME_LENGTH), filter_editbox(120)
472 {
473 this->list_pos = SLP_INVALID;
474 this->server = nullptr;
475
476 this->lock_offset = 5;
477 this->blot_offset = this->lock_offset + 3 + GetSpriteSize(SPR_LOCK).width;
478 this->flag_offset = this->blot_offset + 2 + GetSpriteSize(SPR_BLOT).width;
479
480 this->CreateNestedTree();
481 this->vscroll = this->GetScrollbar(WID_NG_SCROLLBAR);
482 this->FinishInitNested(WN_NETWORK_WINDOW_GAME);
483
484 this->querystrings[WID_NG_CLIENT] = &this->name_editbox;
485 this->name_editbox.text.Assign(_settings_client.network.client_name.c_str());
486
487 this->querystrings[WID_NG_FILTER] = &this->filter_editbox;
488 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
489 this->SetFocusedWidget(WID_NG_FILTER);
490
491 /* As the Game Coordinator doesn't support "websocket" servers yet, we
492 * let "os/emscripten/pre.js" hardcode a list of servers people can
493 * join. This means the serverlist is curated for now, but it is the
494 * best we can offer. */
495 #ifdef __EMSCRIPTEN__
496 EM_ASM(if (window["openttd_server_list"]) openttd_server_list());
497 #endif
498
499 this->last_joined = NetworkAddServer(_settings_client.network.last_joined, false);
500 this->server = this->last_joined;
501
502 this->requery_timer.SetInterval(NETWORK_LIST_REFRESH_DELAY * 1000);
503
504 this->servers.SetListing(this->last_sorting);
505 this->servers.SetSortFuncs(this->sorter_funcs);
506 this->servers.SetFilterFuncs(this->filter_funcs);
507 this->servers.ForceRebuild();
508 }
509
510 ~NetworkGameWindow()
511 {
512 this->last_sorting = this->servers.GetListing();
513 }
514
515 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
516 {
517 switch (widget) {
518 case WID_NG_MATRIX:
519 resize->height = WD_MATRIX_TOP + std::max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
520 fill->height = resize->height;
521 size->height = 12 * resize->height;
522 break;
523
524 case WID_NG_LASTJOINED:
525 size->height = WD_MATRIX_TOP + std::max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
526 break;
527
528 case WID_NG_LASTJOINED_SPACER:
529 size->width = NWidgetScrollbar::GetVerticalDimension().width;
530 break;
531
532 case WID_NG_NAME:
533 size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
534 break;
535
536 case WID_NG_CLIENTS:
537 size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
538 SetDParamMaxValue(0, MAX_CLIENTS);
539 SetDParamMaxValue(1, MAX_CLIENTS);
540 SetDParamMaxValue(2, MAX_COMPANIES);
541 SetDParamMaxValue(3, MAX_COMPANIES);
542 *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE));
543 break;
544
545 case WID_NG_MAPSIZE:
546 size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
547 SetDParamMaxValue(0, MAX_MAP_SIZE);
548 SetDParamMaxValue(1, MAX_MAP_SIZE);
549 *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT));
550 break;
551
552 case WID_NG_DATE:
553 case WID_NG_YEARS:
554 size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
555 SetDParamMaxValue(0, 5);
556 *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
557 break;
558 }
559 }
560
561 void DrawWidget(const Rect &r, int widget) const override
562 {
563 switch (widget) {
564 case WID_NG_MATRIX: {
565 uint16 y = r.top;
566
567 const int max = std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.size());
568
569 for (int i = this->vscroll->GetPosition(); i < max; ++i) {
570 const NetworkGameList *ngl = this->servers[i];
571 this->DrawServerLine(ngl, y, ngl == this->server);
572 y += this->resize.step_height;
573 }
574 break;
575 }
576
577 case WID_NG_LASTJOINED:
578 /* Draw the last joined server, if any */
579 if (this->last_joined != nullptr) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
580 break;
581
582 case WID_NG_DETAILS:
583 this->DrawDetails(r);
584 break;
585
586 case WID_NG_NAME:
587 case WID_NG_CLIENTS:
588 case WID_NG_MAPSIZE:
589 case WID_NG_DATE:
590 case WID_NG_YEARS:
591 case WID_NG_INFO:
592 if (widget - WID_NG_NAME == this->servers.SortType()) this->DrawSortButtonState(widget, this->servers.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
593 break;
594 }
595 }
596
597
598 void OnPaint() override
599 {
600 if (this->servers.NeedRebuild()) {
601 this->BuildGUINetworkGameList();
602 }
603 if (this->servers.NeedResort()) {
604 this->SortNetworkGameList();
605 }
606
607 NetworkGameList *sel = this->server;
608 /* 'Refresh' button invisible if no server selected */
609 this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
610 /* 'Join' button disabling conditions */
611 this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
612 sel->status != NGLS_ONLINE || // Server offline
613 sel->info.clients_on >= sel->info.clients_max || // Server full
614 !sel->info.compatible); // Revision mismatch
615
616 this->SetWidgetLoweredState(WID_NG_REFRESH, sel != nullptr && sel->refreshing);
617
618 /* 'NewGRF Settings' button invisible if no NewGRF is used */
619 this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr);
620 this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
621
622 #ifdef __EMSCRIPTEN__
623 this->SetWidgetDisabledState(WID_NG_SEARCH_INTERNET, true);
624 this->SetWidgetDisabledState(WID_NG_SEARCH_LAN, true);
625 this->SetWidgetDisabledState(WID_NG_ADD, true);
626 this->SetWidgetDisabledState(WID_NG_START, true);
627 #endif
628
629 this->DrawWidgets();
630 }
631
632 void DrawDetails(const Rect &r) const
633 {
634 NetworkGameList *sel = this->server;
635
636 const int detail_height = 6 + 8 + 6 + 3 * FONT_HEIGHT_NORMAL;
637
638 /* Draw the right menu */
639 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE);
640 if (sel == nullptr) {
641 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
642 } else if (sel->status != NGLS_ONLINE) {
643 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
644
645 StringID message = INVALID_STRING_ID;
646 switch (sel->status) {
647 case NGLS_OFFLINE: message = STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; break;
648 case NGLS_FULL: message = STR_NETWORK_SERVER_LIST_SERVER_FULL; break;
649 case NGLS_BANNED: message = STR_NETWORK_SERVER_LIST_SERVER_BANNED; break;
650 case NGLS_TOO_OLD: message = STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD; break;
651
652 /* Handled by the if-case above. */
653 case NGLS_ONLINE: NOT_REACHED();
654 }
655 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
656 } else { // show game info
657
658 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
659 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
660
661 uint16 y = r.top + detail_height + 4;
662
663 SetDParam(0, sel->info.clients_on);
664 SetDParam(1, sel->info.clients_max);
665 SetDParam(2, sel->info.companies_on);
666 SetDParam(3, sel->info.companies_max);
667 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CLIENTS);
668 y += FONT_HEIGHT_NORMAL;
669
670 SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + sel->info.landscape);
671 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE); // landscape
672 y += FONT_HEIGHT_NORMAL;
673
674 SetDParam(0, sel->info.map_width);
675 SetDParam(1, sel->info.map_height);
676 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE); // map size
677 y += FONT_HEIGHT_NORMAL;
678
679 SetDParamStr(0, sel->info.server_revision);
680 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_VERSION); // server version
681 y += FONT_HEIGHT_NORMAL;
682
683 SetDParamStr(0, sel->connection_string);
684 StringID invite_or_address = StrStartsWith(sel->connection_string, "+") ? STR_NETWORK_SERVER_LIST_INVITE_CODE : STR_NETWORK_SERVER_LIST_SERVER_ADDRESS;
685 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, invite_or_address); // server address / invite code
686 y += FONT_HEIGHT_NORMAL;
687
688 SetDParam(0, sel->info.start_date);
689 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE); // start date
690 y += FONT_HEIGHT_NORMAL;
691
692 SetDParam(0, sel->info.game_date);
693 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE); // current date
694 y += FONT_HEIGHT_NORMAL;
695
696 if (sel->info.gamescript_version != -1) {
697 SetDParamStr(0, sel->info.gamescript_name);
698 SetDParam(1, sel->info.gamescript_version);
699 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_GAMESCRIPT); // gamescript name and version
700 y += FONT_HEIGHT_NORMAL;
701 }
702
703 y += WD_PAR_VSEP_NORMAL;
704
705 if (!sel->info.compatible) {
706 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, sel->info.version_compatible ? STR_NETWORK_SERVER_LIST_GRF_MISMATCH : STR_NETWORK_SERVER_LIST_VERSION_MISMATCH, TC_FROMSTRING, SA_HOR_CENTER); // server mismatch
707 } else if (sel->info.clients_on == sel->info.clients_max) {
708 /* Show: server full, when clients_on == max_clients */
709 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_SERVER_FULL, TC_FROMSTRING, SA_HOR_CENTER); // server full
710 } else if (sel->info.use_password) {
711 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_PASSWORD, TC_FROMSTRING, SA_HOR_CENTER); // password warning
712 }
713 }
714 }
715
716 void OnClick(Point pt, int widget, int click_count) override
717 {
718 switch (widget) {
719 case WID_NG_CANCEL: // Cancel button
720 CloseWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME);
721 break;
722
723 case WID_NG_NAME: // Sort by name
724 case WID_NG_CLIENTS: // Sort by connected clients
725 case WID_NG_MAPSIZE: // Sort by map size
726 case WID_NG_DATE: // Sort by date
727 case WID_NG_YEARS: // Sort by years
728 case WID_NG_INFO: // Connectivity (green dot)
729 if (this->servers.SortType() == widget - WID_NG_NAME) {
730 this->servers.ToggleSortOrder();
731 if (this->list_pos != SLP_INVALID) this->list_pos = (ServerListPosition)this->servers.size() - this->list_pos - 1;
732 } else {
733 this->servers.SetSortType(widget - WID_NG_NAME);
734 this->servers.ForceResort();
735 this->SortNetworkGameList();
736 }
737 this->ScrollToSelectedServer();
738 this->SetDirty();
739 break;
740
741 case WID_NG_MATRIX: { // Show available network games
742 uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NG_MATRIX);
743 this->server = (id_v < this->servers.size()) ? this->servers[id_v] : nullptr;
744 this->list_pos = (server == nullptr) ? SLP_INVALID : id_v;
745 this->SetDirty();
746
747 /* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
748 if (click_count > 1 && !this->IsWidgetDisabled(WID_NG_JOIN)) this->OnClick(pt, WID_NG_JOIN, 1);
749 break;
750 }
751
752 case WID_NG_LASTJOINED: {
753 if (this->last_joined != nullptr) {
754 this->server = this->last_joined;
755
756 /* search the position of the newly selected server */
757 this->UpdateListPos();
758 this->ScrollToSelectedServer();
759 this->SetDirty();
760
761 /* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
762 if (click_count > 1 && !this->IsWidgetDisabled(WID_NG_JOIN)) this->OnClick(pt, WID_NG_JOIN, 1);
763 }
764 break;
765 }
766
767 case WID_NG_SEARCH_INTERNET:
768 _network_coordinator_client.GetListing();
769 this->searched_internet = true;
770 break;
771
772 case WID_NG_SEARCH_LAN:
773 NetworkUDPSearchGame();
774 break;
775
776 case WID_NG_ADD: // Add a server
777 SetDParamStr(0, _settings_client.network.connect_to_ip);
778 ShowQueryString(
779 STR_JUST_RAW_STRING,
780 STR_NETWORK_SERVER_LIST_ENTER_SERVER_ADDRESS,
781 NETWORK_HOSTNAME_PORT_LENGTH, // maximum number of characters including '\0'
782 this, CS_ALPHANUMERAL, QSF_ACCEPT_UNCHANGED);
783 break;
784
785 case WID_NG_START: // Start server
786 ShowNetworkStartServerWindow();
787 break;
788
789 case WID_NG_JOIN: // Join Game
790 if (this->server != nullptr) {
791 NetworkClientConnectGame(this->server->connection_string, COMPANY_SPECTATOR);
792 }
793 break;
794
795 case WID_NG_REFRESH: // Refresh
796 if (this->server != nullptr && !this->server->refreshing) NetworkQueryServer(this->server->connection_string);
797 break;
798
799 case WID_NG_NEWGRF: // NewGRF Settings
800 if (this->server != nullptr) ShowNewGRFSettings(false, false, false, &this->server->info.grfconfig);
801 break;
802
803 case WID_NG_NEWGRF_MISSING: // Find missing content online
804 if (this->server != nullptr) ShowMissingContentWindow(this->server->info.grfconfig);
805 break;
806 }
807 }
808
814 void OnInvalidateData(int data = 0, bool gui_scope = true) override
815 {
816 this->servers.ForceRebuild();
817 this->SetDirty();
818 }
819
820 EventState OnKeyPress(WChar key, uint16 keycode) override
821 {
822 EventState state = ES_NOT_HANDLED;
823
824 /* handle up, down, pageup, pagedown, home and end */
825 if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == ES_HANDLED) {
826 if (this->list_pos == SLP_INVALID) return ES_HANDLED;
827
828 this->server = this->servers[this->list_pos];
829
830 /* Scroll to the new server if it is outside the current range. */
831 this->ScrollToSelectedServer();
832
833 /* redraw window */
834 this->SetDirty();
835 return ES_HANDLED;
836 }
837
838 if (this->server != nullptr) {
839 if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
840 NetworkGameListRemoveItem(this->server);
841 if (this->server == this->last_joined) this->last_joined = nullptr;
842 this->server = nullptr;
843 this->list_pos = SLP_INVALID;
844 }
845 }
846
847 return state;
848 }
849
850 void OnEditboxChanged(int wid) override
851 {
852 switch (wid) {
853 case WID_NG_FILTER: {
854 this->servers.ForceRebuild();
855 this->BuildGUINetworkGameList();
856 this->ScrollToSelectedServer();
857 this->SetDirty();
858 break;
859 }
860
861 case WID_NG_CLIENT:
862 /* Validation of the name will happen once the user tries to join or start a game, as getting
863 * error messages while typing (e.g. when you clear the name) defeats the purpose of the check. */
864 _settings_client.network.client_name = this->name_editbox.text.buf;
865 break;
866 }
867 }
868
869 void OnQueryTextFinished(char *str) override
870 {
871 if (!StrEmpty(str)) {
872 _settings_client.network.connect_to_ip = str;
873 NetworkAddServer(str);
874 NetworkRebuildHostList();
875 }
876 }
877
878 void OnResize() override
879 {
880 this->vscroll->SetCapacityFromWidget(this, WID_NG_MATRIX);
881 }
882
883 void OnRealtimeTick(uint delta_ms) override
884 {
885 if (!this->searched_internet) return;
886 if (!this->requery_timer.Elapsed(delta_ms)) return;
887 this->requery_timer.SetInterval(NETWORK_LIST_REFRESH_DELAY * 1000);
888
889 _network_coordinator_client.GetListing();
890 }
891 };
892
893 Listing NetworkGameWindow::last_sorting = {false, 5};
894 GUIGameServerList::SortFunction * const NetworkGameWindow::sorter_funcs[] = {
895 &NGameNameSorter,
896 &NGameClientSorter,
897 &NGameMapSizeSorter,
898 &NGameDateSorter,
899 &NGameYearsSorter,
900 &NGameAllowedSorter
901 };
902
903 GUIGameServerList::FilterFunction * const NetworkGameWindow::filter_funcs[] = {
904 &NGameSearchFilter
905 };
906
907 static NWidgetBase *MakeResizableHeader(int *biggest_index)
908 {
909 *biggest_index = std::max<int>(*biggest_index, WID_NG_INFO);
910 return new NWidgetServerListHeader();
911 }
912
913 static const NWidgetPart _nested_network_game_widgets[] = {
914 /* TOP */
915 NWidget(NWID_HORIZONTAL),
916 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
917 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_NETWORK_SERVER_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
918 NWidget(WWT_DEFSIZEBOX, COLOUR_LIGHT_BLUE),
919 EndContainer(),
920 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NG_MAIN),
921 NWidget(NWID_VERTICAL), SetPIP(10, 7, 0),
922 NWidget(NWID_HORIZONTAL), SetPIP(10, 7, 10),
923 /* LEFT SIDE */
924 NWidget(NWID_VERTICAL), SetPIP(0, 7, 0),
925 NWidget(NWID_HORIZONTAL), SetPIP(0, 7, 0),
926 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NG_FILTER_LABEL), SetDataTip(STR_LIST_FILTER_TITLE, STR_NULL),
927 NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NG_FILTER), SetMinimalSize(251, 12), SetFill(1, 0), SetResize(1, 0),
928 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
929 EndContainer(),
930 NWidget(NWID_HORIZONTAL),
931 NWidget(NWID_VERTICAL),
932 NWidgetFunction(MakeResizableHeader),
933 NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, WID_NG_MATRIX), SetResize(1, 1), SetFill(1, 0),
934 SetMatrixDataTip(1, 0, STR_NETWORK_SERVER_LIST_CLICK_GAME_TO_SELECT), SetScrollbar(WID_NG_SCROLLBAR),
935 EndContainer(),
936 NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NG_SCROLLBAR),
937 EndContainer(),
938 NWidget(NWID_VERTICAL),
939 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NG_LASTJOINED_LABEL), SetFill(1, 0),
940 SetDataTip(STR_NETWORK_SERVER_LIST_LAST_JOINED_SERVER, STR_NULL), SetResize(1, 0),
941 NWidget(NWID_HORIZONTAL),
942 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NG_LASTJOINED), SetFill(1, 0), SetResize(1, 0),
943 SetDataTip(0x0, STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST),
944 EndContainer(),
945 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NG_LASTJOINED_SPACER), SetFill(0, 0),
946 EndContainer(),
947 EndContainer(),
948 EndContainer(),
949 /* RIGHT SIDE */
950 NWidget(NWID_VERTICAL), SetPIP(0, 7, 0),
951 NWidget(NWID_HORIZONTAL), SetPIP(0, 7, 0),
952 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NG_CLIENT_LABEL), SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME, STR_NULL),
953 NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NG_CLIENT), SetMinimalSize(151, 12), SetFill(1, 0), SetResize(1, 0),
954 SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
955 EndContainer(),
956 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NG_DETAILS),
957 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(5, 5, 5),
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), // Make sure it's at least this wide
959 NWidget(NWID_HORIZONTAL, NC_NONE), SetPIP(5, 5, 5),
960 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NG_NEWGRF_MISSING_SEL),
961 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NEWGRF_MISSING), SetFill(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON, STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP),
962 NWidget(NWID_SPACER), SetFill(1, 0),
963 EndContainer(),
964 EndContainer(),
965 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(5, 5, 5),
966 NWidget(NWID_SPACER), SetFill(1, 0),
967 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NG_NEWGRF_SEL),
968 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NEWGRF), SetFill(1, 0), SetDataTip(STR_INTRO_NEWGRF_SETTINGS, STR_NULL),
969 NWidget(NWID_SPACER), SetFill(1, 0),
970 EndContainer(),
971 EndContainer(),
972 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(5, 5, 5),
973 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_JOIN), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_JOIN_GAME, STR_NULL),
974 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_REFRESH), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_REFRESH, STR_NETWORK_SERVER_LIST_REFRESH_TOOLTIP),
975 EndContainer(),
976 EndContainer(),
977 EndContainer(),
978 EndContainer(),
979 EndContainer(),
980 /* BOTTOM */
981 NWidget(NWID_HORIZONTAL),
982 NWidget(NWID_VERTICAL),
983 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 7, 4),
984 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_SEARCH_INTERNET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_SEARCH_SERVER_INTERNET, STR_NETWORK_SERVER_LIST_SEARCH_SERVER_INTERNET_TOOLTIP),
985 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_SEARCH_LAN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_SEARCH_SERVER_LAN, STR_NETWORK_SERVER_LIST_SEARCH_SERVER_LAN_TOOLTIP),
986 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_ADD), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_ADD_SERVER, STR_NETWORK_SERVER_LIST_ADD_SERVER_TOOLTIP),
987 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_START), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NETWORK_SERVER_LIST_START_SERVER, STR_NETWORK_SERVER_LIST_START_SERVER_TOOLTIP),
988 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
989 EndContainer(),
990 NWidget(NWID_SPACER), SetMinimalSize(0, 6), SetResize(1, 0), SetFill(1, 0),
991 EndContainer(),
992 NWidget(NWID_VERTICAL),
993 NWidget(NWID_SPACER), SetFill(0, 1),
994 NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE),
995 EndContainer(),
996 EndContainer(),
997 EndContainer(),
998 EndContainer(),
999 };
1000
1001 static WindowDesc _network_game_window_desc(
1002 WDP_CENTER, "list_servers", 1000, 730,
1003 WC_NETWORK_WINDOW, WC_NONE,
1004 0,
1005 _nested_network_game_widgets, lengthof(_nested_network_game_widgets)
1006 );
1007
1008 void ShowNetworkGameWindow()
1009 {
1010 static bool first = true;
1011 CloseWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_START);
1012
1013 /* Only show once */
1014 if (first) {
1015 first = false;
1016 /* Add all servers from the config file to our list. */
1017 for (const auto &iter : _network_host_list) {
1018 NetworkAddServer(iter);
1019 }
1020 }
1021
1022 new NetworkGameWindow(&_network_game_window_desc);
1023 }
1024
1025 struct NetworkStartServerWindow : public Window {
1026 byte widget_id;
1027 QueryString name_editbox;
1028
1029 NetworkStartServerWindow(WindowDesc *desc) : Window(desc), name_editbox(NETWORK_NAME_LENGTH)
1030 {
1031 this->InitNested(WN_NETWORK_WINDOW_START);
1032
1033 this->querystrings[WID_NSS_GAMENAME] = &this->name_editbox;
1034 this->name_editbox.text.Assign(_settings_client.network.server_name.c_str());
1035
1036 this->SetFocusedWidget(WID_NSS_GAMENAME);
1037 }
1038
1039 void SetStringParameters(int widget) const override
1040 {
1041 switch (widget) {
1042 case WID_NSS_CONNTYPE_BTN:
1043 SetDParam(0, STR_NETWORK_SERVER_VISIBILITY_LOCAL + _settings_client.network.server_game_type);
1044 break;
1045
1046 case WID_NSS_CLIENTS_TXT:
1047 SetDParam(0, _settings_client.network.max_clients);
1048 break;
1049
1050 case WID_NSS_COMPANIES_TXT:
1051 SetDParam(0, _settings_client.network.max_companies);
1052 break;
1053 }
1054 }
1055
1056 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1057 {
1058 switch (widget) {
1059 case WID_NSS_CONNTYPE_BTN:
1060 *size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY));
1061 size->width += padding.width;
1062 size->height += padding.height;
1063 break;
1064 }
1065 }
1066
1067 void DrawWidget(const Rect &r, int widget) const override
1068 {
1069 switch (widget) {
1070 case WID_NSS_SETPWD:
1071 /* If password is set, draw red '*' next to 'Set password' button. */
1072 if (!_settings_client.network.server_password.empty()) DrawString(r.right + WD_FRAMERECT_LEFT, this->width - WD_FRAMERECT_RIGHT, r.top, "*", TC_RED);
1073 }
1074 }
1075
1076 void OnClick(Point pt, int widget, int click_count) override
1077 {
1078 switch (widget) {
1079 case WID_NSS_CANCEL: // Cancel button
1080 ShowNetworkGameWindow();
1081 break;
1082
1083 case WID_NSS_SETPWD: // Set password button
1084 this->widget_id = WID_NSS_SETPWD;
1085 SetDParamStr(0, _settings_client.network.server_password);
1086 ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_START_SERVER_SET_PASSWORD, 20, this, CS_ALPHANUMERAL, QSF_NONE);
1087 break;
1088
1089 case WID_NSS_CONNTYPE_BTN: // Connection type
1090 ShowDropDownList(this, BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_NSS_CONNTYPE_BTN);
1091 break;
1092
1093 case WID_NSS_CLIENTS_BTND: case WID_NSS_CLIENTS_BTNU: // Click on up/down button for number of clients
1094 case WID_NSS_COMPANIES_BTND: case WID_NSS_COMPANIES_BTNU: // Click on up/down button for number of companies
1095 /* Don't allow too fast scrolling. */
1096 if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1097 this->HandleButtonClick(widget);
1098 this->SetDirty();
1099 switch (widget) {
1100 default: NOT_REACHED();
1101 case WID_NSS_CLIENTS_BTND: case WID_NSS_CLIENTS_BTNU:
1102 _settings_client.network.max_clients = Clamp(_settings_client.network.max_clients + widget - WID_NSS_CLIENTS_TXT, 2, MAX_CLIENTS);
1103 break;
1104 case WID_NSS_COMPANIES_BTND: case WID_NSS_COMPANIES_BTNU:
1105 _settings_client.network.max_companies = Clamp(_settings_client.network.max_companies + widget - WID_NSS_COMPANIES_TXT, 1, MAX_COMPANIES);
1106 break;
1107 }
1108 }
1109 _left_button_clicked = false;
1110 break;
1111
1112 case WID_NSS_CLIENTS_TXT: // Click on number of clients
1113 this->widget_id = WID_NSS_CLIENTS_TXT;
1114 SetDParam(0, _settings_client.network.max_clients);
1115 ShowQueryString(STR_JUST_INT, STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS, 4, this, CS_NUMERAL, QSF_NONE);
1116 break;
1117
1118 case WID_NSS_COMPANIES_TXT: // Click on number of companies
1119 this->widget_id = WID_NSS_COMPANIES_TXT;
1120 SetDParam(0, _settings_client.network.max_companies);
1121 ShowQueryString(STR_JUST_INT, STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES, 3, this, CS_NUMERAL, QSF_NONE);
1122 break;
1123
1124 case WID_NSS_GENERATE_GAME: // Start game
1125 if (!CheckServerName()) return;
1126 _is_network_server = true;
1127 if (_ctrl_pressed) {
1128 StartNewGameWithoutGUI(GENERATE_NEW_SEED);
1129 } else {
1130 ShowGenerateLandscape();
1131 }
1132 break;
1133
1134 case WID_NSS_LOAD_GAME:
1135 if (!CheckServerName()) return;
1136 _is_network_server = true;
1137 ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD);
1138 break;
1139
1140 case WID_NSS_PLAY_SCENARIO:
1141 if (!CheckServerName()) return;
1142 _is_network_server = true;
1143 ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD);
1144 break;
1145
1146 case WID_NSS_PLAY_HEIGHTMAP:
1147 if (!CheckServerName()) return;
1148 _is_network_server = true;
1149 ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD);
1150 break;
1151 }
1152 }
1153
1154 void OnDropdownSelect(int widget, int index) override
1155 {
1156 switch (widget) {
1157 case WID_NSS_CONNTYPE_BTN:
1158 _settings_client.network.server_game_type = (ServerGameType)index;
1159 break;
1160 default:
1161 NOT_REACHED();
1162 }
1163
1164 this->SetDirty();
1165 }
1166
1167 bool CheckServerName()
1168 {
1169 std::string str = this->name_editbox.text.buf;
1170 if (!NetworkValidateServerName(str)) return false;
1171
1172 SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str);
1173 return true;
1174 }
1175
1176 void OnTimeout() override
1177 {
1178 static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WIDGET_LIST_END};
1179 for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1180 if (this->IsWidgetLowered(*widget)) {
1181 this->RaiseWidget(*widget);
1182 this->SetWidgetDirty(*widget);
1183 }
1184 }
1185 }
1186
1187 void OnQueryTextFinished(char *str) override
1188 {
1189 if (str == nullptr) return;
1190
1191 if (this->widget_id == WID_NSS_SETPWD) {
1192 _settings_client.network.server_password = str;
1193 } else {
1194 int32 value = atoi(str);
1195 this->SetWidgetDirty(this->widget_id);
1196 switch (this->widget_id) {
1197 default: NOT_REACHED();
1198 case WID_NSS_CLIENTS_TXT: _settings_client.network.max_clients = Clamp(value, 2, MAX_CLIENTS); break;
1199 case WID_NSS_COMPANIES_TXT: _settings_client.network.max_companies = Clamp(value, 1, MAX_COMPANIES); break;
1200 }
1201 }
1202
1203 this->SetDirty();
1204 }
1205 };
1206
1207 static const NWidgetPart _nested_network_start_server_window_widgets[] = {
1208 NWidget(NWID_HORIZONTAL),
1209 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
1210 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_NETWORK_START_SERVER_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1211 EndContainer(),
1212 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NSS_BACKGROUND),
1213 NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1214 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
1215 NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
1216 /* Game name widgets */
1217 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_GAMENAME_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_NEW_GAME_NAME, STR_NULL),
1218 NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NSS_GAMENAME), SetMinimalSize(10, 12), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_NEW_GAME_NAME_OSKTITLE, STR_NETWORK_START_SERVER_NEW_GAME_NAME_TOOLTIP),
1219 EndContainer(),
1220 EndContainer(),
1221
1222 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
1223 NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
1224 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_CONNTYPE_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_VISIBILITY_LABEL, STR_NULL),
1225 NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_NSS_CONNTYPE_BTN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_START_SERVER_VISIBILITY_TOOLTIP),
1226 EndContainer(),
1227 NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
1228 NWidget(NWID_SPACER), SetFill(1, 1),
1229 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_SETPWD), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_SET_PASSWORD, STR_NETWORK_START_SERVER_PASSWORD_TOOLTIP),
1230 EndContainer(),
1231 EndContainer(),
1232
1233 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
1234 NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
1235 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_CLIENTS_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS, STR_NULL),
1236 NWidget(NWID_HORIZONTAL),
1237 NWidget(WWT_IMGBTN, COLOUR_LIGHT_BLUE, WID_NSS_CLIENTS_BTND), SetMinimalSize(12, 12), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS_TOOLTIP),
1238 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_NSS_CLIENTS_TXT), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_CLIENTS_SELECT, STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS_TOOLTIP),
1239 NWidget(WWT_IMGBTN, COLOUR_LIGHT_BLUE, WID_NSS_CLIENTS_BTNU), SetMinimalSize(12, 12), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS_TOOLTIP),
1240 EndContainer(),
1241 EndContainer(),
1242
1243 NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
1244 NWidget(WWT_TEXT, COLOUR_LIGHT_BLUE, WID_NSS_COMPANIES_LABEL), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES, STR_NULL),
1245 NWidget(NWID_HORIZONTAL),
1246 NWidget(WWT_IMGBTN, COLOUR_LIGHT_BLUE, WID_NSS_COMPANIES_BTND), SetMinimalSize(12, 12), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES_TOOLTIP),
1247 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_NSS_COMPANIES_TXT), SetFill(1, 0), SetDataTip(STR_NETWORK_START_SERVER_COMPANIES_SELECT, STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES_TOOLTIP),
1248 NWidget(WWT_IMGBTN, COLOUR_LIGHT_BLUE, WID_NSS_COMPANIES_BTNU), SetMinimalSize(12, 12), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_NETWORK_START_SERVER_NUMBER_OF_COMPANIES_TOOLTIP),
1249 EndContainer(),
1250 EndContainer(),
1251 EndContainer(),
1252
1253 /* 'generate game' and 'load game' buttons */
1254 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
1255 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_GENERATE_GAME), SetDataTip(STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME), SetFill(1, 0),
1256 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_LOAD_GAME), SetDataTip(STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME), SetFill(1, 0),
1257 EndContainer(),
1258
1259 /* 'play scenario' and 'play heightmap' buttons */
1260 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 6, 10),
1261 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_PLAY_SCENARIO), SetDataTip(STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO), SetFill(1, 0),
1262 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_PLAY_HEIGHTMAP), SetDataTip(STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP), SetFill(1, 0),
1263 EndContainer(),
1264
1265 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
1266 NWidget(NWID_SPACER), SetFill(1, 0),
1267 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NSS_CANCEL), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), SetMinimalSize(128, 12),
1268 NWidget(NWID_SPACER), SetFill(1, 0),
1269 EndContainer(),
1270 EndContainer(),
1271 EndContainer(),
1272 };
1273
1274 static WindowDesc _network_start_server_window_desc(
1275 WDP_CENTER, nullptr, 0, 0,
1276 WC_NETWORK_WINDOW, WC_NONE,
1277 0,
1278 _nested_network_start_server_window_widgets, lengthof(_nested_network_start_server_window_widgets)
1279 );
1280
1281 static void ShowNetworkStartServerWindow()
1282 {
1283 if (!NetworkValidateOurClientName()) return;
1284
1285 CloseWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME);
1286
1287 new NetworkStartServerWindow(&_network_start_server_window_desc);
1288 }
1289
1290 /* The window below gives information about the connected clients
1291 * and also makes able to kick them (if server) and stuff like that. */
1292
1293 extern void DrawCompanyIcon(CompanyID cid, int x, int y);
1294
1295 static const NWidgetPart _nested_client_list_widgets[] = {
1296 NWidget(NWID_HORIZONTAL),
1297 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1298 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1299 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1300 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1301 EndContainer(),
1302 NWidget(WWT_PANEL, COLOUR_GREY),
1303 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER, STR_NULL), SetPadding(4, 4, 0, 4), SetPIP(0, 2, 0),
1304 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
1305 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME, STR_NULL),
1306 NWidget(NWID_SPACER), SetMinimalSize(10, 0),
1307 NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_SERVER_NAME), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1308 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_CL_SERVER_NAME_EDIT), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_SERVER_NAME_EDIT_TOOLTIP),
1309 EndContainer(),
1310 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CL_SERVER_SELECTOR),
1311 NWidget(NWID_VERTICAL),
1312 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
1313 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY, STR_NULL),
1314 NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0), SetResize(1, 0),
1315 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_CL_SERVER_VISIBILITY), SetDataTip(STR_BLACK_STRING, STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY_TOOLTIP),
1316 EndContainer(),
1317 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
1318 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_INVITE_CODE, STR_NULL),
1319 NWidget(NWID_SPACER), SetMinimalSize(10, 0),
1320 NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_SERVER_INVITE_CODE), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_INVITE_CODE_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1321 EndContainer(),
1322 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
1323 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE, STR_NULL),
1324 NWidget(NWID_SPACER), SetMinimalSize(10, 0),
1325 NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_SERVER_CONNECTION_TYPE), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_STRING, STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1326 EndContainer(),
1327 EndContainer(),
1328 EndContainer(),
1329 EndContainer(),
1330 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_PLAYER, STR_NULL), SetPadding(4, 4, 4, 4), SetPIP(0, 2, 0),
1331 NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
1332 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_PLAYER_NAME, STR_NULL),
1333 NWidget(NWID_SPACER), SetMinimalSize(10, 0),
1334 NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_NAME), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_RAW_STRING, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT),
1335 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_CL_CLIENT_NAME_EDIT), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_EDIT_TOOLTIP),
1336 EndContainer(),
1337 EndContainer(),
1338 NWidget(NWID_HORIZONTAL),
1339 NWidget(NWID_VERTICAL),
1340 NWidget(WWT_MATRIX, COLOUR_GREY, WID_CL_MATRIX), SetMinimalSize(180, 0), SetResize(1, 1), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_CL_SCROLLBAR),
1341 NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetPadding(2, 1, 2, 1), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT, STR_NULL),
1342 EndContainer(),
1343 NWidget(NWID_VERTICAL),
1344 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_CL_SCROLLBAR),
1345 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1346 EndContainer(),
1347 EndContainer(),
1348 EndContainer(),
1349 };
1350
1351 static WindowDesc _client_list_desc(
1352 WDP_AUTO, "list_clients", 220, 300,
1353 WC_CLIENT_LIST, WC_NONE,
1354 0,
1355 _nested_client_list_widgets, lengthof(_nested_client_list_widgets)
1356 );
1357
1362 enum DropDownAdmin {
1363 DD_CLIENT_ADMIN_KICK,
1364 DD_CLIENT_ADMIN_BAN,
1365 DD_COMPANY_ADMIN_RESET,
1366 DD_COMPANY_ADMIN_UNLOCK,
1367 };
1368
1374 static void AdminClientKickCallback(Window *w, bool confirmed)
1375 {
1376 if (confirmed) NetworkServerKickClient(_admin_client_id, {});
1377 }
1378
1384 static void AdminClientBanCallback(Window *w, bool confirmed)
1385 {
1386 if (confirmed) NetworkServerKickOrBanIP(_admin_client_id, true, {});
1387 }
1388
1394 static void AdminCompanyResetCallback(Window *w, bool confirmed)
1395 {
1396 if (confirmed) {
1397 if (NetworkCompanyHasClients(_admin_company_id)) return;
1398 DoCommandP(0, CCA_DELETE | _admin_company_id << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
1399 }
1400 }
1401
1407 static void AdminCompanyUnlockCallback(Window *w, bool confirmed)
1408 {
1409 if (confirmed) NetworkServerSetCompanyPassword(_admin_company_id, "", false);
1410 }
1411
1419 class ButtonCommon {
1420 public:
1421 SpriteID sprite;
1422 StringID tooltip;
1423 Colours colour;
1424 bool disabled;
1425 uint height;
1426 uint width;
1427
1428 ButtonCommon(SpriteID sprite, StringID tooltip, Colours colour, bool disabled = false) :
1429 sprite(sprite),
1430 tooltip(tooltip),
1431 colour(colour),
1432 disabled(disabled)
1433 {
1434 Dimension d = GetSpriteSize(sprite);
1435 this->height = d.height + ScaleGUITrad(WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
1436 this->width = d.width + ScaleGUITrad(WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT);
1437 }
1438 virtual ~ButtonCommon() {}
1439
1443 virtual void OnClick(struct NetworkClientListWindow *w, Point pt) = 0;
1444 };
1445
1449 template<typename T>
1450 class Button : public ButtonCommon {
1451 private:
1452 typedef void (*ButtonCallback)(struct NetworkClientListWindow *w, Point pt, T id);
1453 T id;
1454 ButtonCallback proc;
1455
1456 public:
1457 Button(SpriteID sprite, StringID tooltip, Colours colour, T id, ButtonCallback proc, bool disabled = false) :
1458 ButtonCommon(sprite, tooltip, colour, disabled),
1459 id(id),
1460 proc(proc)
1461 {
1462 assert(proc != nullptr);
1463 }
1464
1465 void OnClick(struct NetworkClientListWindow *w, Point pt) override
1466 {
1467 if (this->disabled) return;
1468
1469 this->proc(w, pt, this->id);
1470 }
1471 };
1472
1473 using CompanyButton = Button<CompanyID>;
1474 using ClientButton = Button<ClientID>;
1475
1479 struct NetworkClientListWindow : Window {
1480 private:
1481 ClientListWidgets query_widget;
1482 CompanyID join_company;
1483
1484 ClientID dd_client_id;
1485 CompanyID dd_company_id;
1486
1487 Scrollbar *vscroll;
1488 uint line_height;
1489 uint line_count;
1490 int hover_index;
1491 int player_self_index;
1492 int player_host_index;
1493
1494 std::map<uint, std::vector<std::unique_ptr<ButtonCommon>>> buttons;
1495
1496 static const int CLIENT_OFFSET_LEFT = 12;
1497
1504 static void OnClickCompanyChat(NetworkClientListWindow *w, Point pt, CompanyID company_id)
1505 {
1506 ShowNetworkChatQueryWindow(DESTTYPE_TEAM, company_id);
1507 }
1508
1515 static void OnClickCompanyJoin(NetworkClientListWindow *w, Point pt, CompanyID company_id)
1516 {
1517 if (_network_server) {
1518 NetworkServerDoMove(CLIENT_ID_SERVER, company_id);
1519 MarkWholeScreenDirty();
1520 } else if (NetworkCompanyIsPassworded(company_id)) {
1521 w->query_widget = WID_CL_COMPANY_JOIN;
1522 w->join_company = company_id;
1523 ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_PASSWORD);
1524 } else {
1525 NetworkClientRequestMove(company_id);
1526 }
1527 }
1528
1535 static void OnClickCompanyNew(NetworkClientListWindow *w, Point pt, CompanyID company_id)
1536 {
1537 if (_network_server) {
1538 DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
1539 } else {
1540 NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, {}, _local_company);
1541 }
1542 }
1543
1550 static void OnClickClientAdmin(NetworkClientListWindow *w, Point pt, ClientID client_id)
1551 {
1552 DropDownList list;
1553 list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_KICK, DD_CLIENT_ADMIN_KICK, false));
1554 list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN, DD_CLIENT_ADMIN_BAN, false));
1555
1556 Rect wi_rect;
1557 wi_rect.left = pt.x;
1558 wi_rect.right = pt.x;
1559 wi_rect.top = pt.y;
1560 wi_rect.bottom = pt.y;
1561
1562 w->dd_client_id = client_id;
1563 ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true, true);
1564 }
1565
1572 static void OnClickCompanyAdmin(NetworkClientListWindow *w, Point pt, CompanyID company_id)
1573 {
1574 DropDownList list;
1575 list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, DD_COMPANY_ADMIN_RESET, NetworkCompanyHasClients(company_id)));
1576 list.emplace_back(new DropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK, DD_COMPANY_ADMIN_UNLOCK, !NetworkCompanyIsPassworded(company_id)));
1577
1578 Rect wi_rect;
1579 wi_rect.left = pt.x;
1580 wi_rect.right = pt.x;
1581 wi_rect.top = pt.y;
1582 wi_rect.bottom = pt.y;
1583
1584 w->dd_company_id = company_id;
1585 ShowDropDownListAt(w, std::move(list), -1, WID_CL_MATRIX, wi_rect, COLOUR_GREY, true, true);
1586 }
1593 static void OnClickClientChat(NetworkClientListWindow *w, Point pt, ClientID client_id)
1594 {
1595 ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, client_id);
1596 }
1597
1603 void RebuildListCompany(CompanyID company_id, CompanyID client_playas)
1604 {
1605 ButtonCommon *chat_button = new CompanyButton(SPR_CHAT, company_id == COMPANY_SPECTATOR ? STR_NETWORK_CLIENT_LIST_CHAT_SPECTATOR_TOOLTIP : STR_NETWORK_CLIENT_LIST_CHAT_COMPANY_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyChat);
1606
1607 if (_network_server) this->buttons[line_count].emplace_back(new CompanyButton(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP, COLOUR_RED, company_id, &NetworkClientListWindow::OnClickCompanyAdmin, company_id == COMPANY_SPECTATOR));
1608 this->buttons[line_count].emplace_back(chat_button);
1609 if (client_playas != company_id) this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin, company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai));
1610
1611 this->line_count += 1;
1612
1613 bool has_players = false;
1614 for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
1615 if (ci->client_playas != company_id) continue;
1616 has_players = true;
1617
1618 if (_network_server) this->buttons[line_count].emplace_back(new ClientButton(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOOLTIP, COLOUR_RED, ci->client_id, &NetworkClientListWindow::OnClickClientAdmin, _network_own_client_id == ci->client_id));
1619 if (_network_own_client_id != ci->client_id) this->buttons[line_count].emplace_back(new ClientButton(SPR_CHAT, STR_NETWORK_CLIENT_LIST_CHAT_CLIENT_TOOLTIP, COLOUR_ORANGE, ci->client_id, &NetworkClientListWindow::OnClickClientChat));
1620
1621 if (ci->client_id == _network_own_client_id) {
1622 this->player_self_index = this->line_count;
1623 } else if (ci->client_id == CLIENT_ID_SERVER) {
1624 this->player_host_index = this->line_count;
1625 }
1626
1627 this->line_count += 1;
1628 }
1629
1630 /* Disable the chat button when there are players in this company. */
1631 chat_button->disabled = !has_players;
1632 }
1633
1637 void RebuildList()
1638 {
1639 const NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
1640 CompanyID client_playas = own_ci == nullptr ? COMPANY_SPECTATOR : own_ci->client_playas;
1641
1642 this->buttons.clear();
1643 this->line_count = 0;
1644 this->player_host_index = -1;
1645 this->player_self_index = -1;
1646
1647 /* As spectator, show a line to create a new company. */
1648 if (client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) {
1649 this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP, COLOUR_ORANGE, COMPANY_SPECTATOR, &NetworkClientListWindow::OnClickCompanyNew));
1650 this->line_count += 1;
1651 }
1652
1653 if (client_playas != COMPANY_SPECTATOR) {
1654 this->RebuildListCompany(client_playas, client_playas);
1655 }
1656
1657 /* Companies */
1658 for (const Company *c : Company::Iterate()) {
1659 if (c->index == client_playas) continue;
1660
1661 this->RebuildListCompany(c->index, client_playas);
1662 }
1663
1664 /* Spectators */
1665 this->RebuildListCompany(COMPANY_SPECTATOR, client_playas);
1666
1667 this->vscroll->SetCount(this->line_count);
1668 }
1669
1675 ButtonCommon *GetButtonAtPoint(Point pt)
1676 {
1677 uint index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CL_MATRIX);
1678 NWidgetBase *widget_matrix = this->GetWidget<NWidgetBase>(WID_CL_MATRIX);
1679
1680 bool rtl = _current_text_dir == TD_RTL;
1681 uint x = rtl ? (uint)widget_matrix->pos_x + WD_FRAMERECT_LEFT : widget_matrix->current_x - WD_FRAMERECT_RIGHT;
1682
1683 /* Find the buttons for this row. */
1684 auto button_find = this->buttons.find(index);
1685 if (button_find == this->buttons.end()) return nullptr;
1686
1687 /* Check if we want to display a tooltip for any of the buttons. */
1688 for (auto &button : button_find->second) {
1689 uint left = rtl ? x : x - button->width;
1690 uint right = rtl ? x + button->width : x;
1691
1692 if (IsInsideMM(pt.x, left, right)) {
1693 return button.get();
1694 }
1695
1696 int width = button->width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
1697 x += rtl ? width : -width;
1698 }
1699
1700 return nullptr;
1701 }
1702
1703 public:
1704 NetworkClientListWindow(WindowDesc *desc, WindowNumber window_number) :
1705 Window(desc),
1706 hover_index(-1),
1707 player_self_index(-1),
1708 player_host_index(-1)
1709 {
1710 this->CreateNestedTree();
1711 this->vscroll = this->GetScrollbar(WID_CL_SCROLLBAR);
1712 this->OnInvalidateData();
1713 this->FinishInitNested(window_number);
1714 }
1715
1716 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1717 {
1718 this->RebuildList();
1719
1720 /* Currently server information is not sync'd to clients, so we cannot show it on clients. */
1721 this->GetWidget<NWidgetStacked>(WID_CL_SERVER_SELECTOR)->SetDisplayedPlane(_network_server ? 0 : SZSP_HORIZONTAL);
1722 this->SetWidgetDisabledState(WID_CL_SERVER_NAME_EDIT, !_network_server);
1723 }
1724
1725 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1726 {
1727 switch (widget) {
1728 case WID_CL_SERVER_VISIBILITY:
1729 *size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY));
1730 size->width += padding.width;
1731 size->height += padding.height;
1732 break;
1733
1734 case WID_CL_MATRIX: {
1735 uint height = std::max({GetSpriteSize(SPR_COMPANY_ICON).height, GetSpriteSize(SPR_JOIN).height, GetSpriteSize(SPR_ADMIN).height, GetSpriteSize(SPR_CHAT).height});
1736 height += ScaleGUITrad(WD_FRAMERECT_TOP) + ScaleGUITrad(WD_FRAMERECT_BOTTOM);
1737 this->line_height = std::max(height, (uint)FONT_HEIGHT_NORMAL) + ScaleGUITrad(WD_MATRIX_TOP + WD_MATRIX_BOTTOM);
1738
1739 resize->width = 1;
1740 resize->height = this->line_height;
1741 fill->height = this->line_height;
1742 size->height = std::max(size->height, 5 * this->line_height);
1743 break;
1744 }
1745 }
1746 }
1747
1748 void OnResize() override
1749 {
1750 this->vscroll->SetCapacityFromWidget(this, WID_CL_MATRIX);
1751 }
1752
1753 void SetStringParameters(int widget) const override
1754 {
1755 switch (widget) {
1756 case WID_CL_SERVER_NAME:
1757 SetDParamStr(0, _network_server ? _settings_client.network.server_name : _network_server_name);
1758 break;
1759
1760 case WID_CL_SERVER_VISIBILITY:
1761 SetDParam(0, STR_NETWORK_SERVER_VISIBILITY_LOCAL + _settings_client.network.server_game_type);
1762 break;
1763
1764 case WID_CL_SERVER_INVITE_CODE: {
1765 static std::string empty = {};
1766 SetDParamStr(0, _network_server_connection_type == CONNECTION_TYPE_UNKNOWN ? empty : _network_server_invite_code);
1767 break;
1768 }
1769
1770 case WID_CL_SERVER_CONNECTION_TYPE:
1771 SetDParam(0, STR_NETWORK_CLIENT_LIST_SERVER_CONNECTION_TYPE_UNKNOWN + _network_server_connection_type);
1772 break;
1773
1774 case WID_CL_CLIENT_NAME:
1775 SetDParamStr(0, _settings_client.network.client_name);
1776 break;
1777
1778 case WID_CL_CLIENT_COMPANY_COUNT:
1779 SetDParam(0, NetworkClientInfo::GetNumItems());
1780 SetDParam(1, Company::GetNumItems());
1781 break;
1782 }
1783 }
1784
1785 void OnClick(Point pt, int widget, int click_count) override
1786 {
1787 switch (widget) {
1788 case WID_CL_SERVER_NAME_EDIT:
1789 if (!_network_server) break;
1790
1791 this->query_widget = WID_CL_SERVER_NAME_EDIT;
1792 SetDParamStr(0, _settings_client.network.server_name);
1793 ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_NAME_QUERY_CAPTION, NETWORK_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS);
1794 break;
1795
1796 case WID_CL_CLIENT_NAME_EDIT:
1797 this->query_widget = WID_CL_CLIENT_NAME_EDIT;
1798 SetDParamStr(0, _settings_client.network.client_name);
1799 ShowQueryString(STR_JUST_RAW_STRING, STR_NETWORK_CLIENT_LIST_PLAYER_NAME_QUERY_CAPTION, NETWORK_CLIENT_NAME_LENGTH, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS);
1800 break;
1801
1802 case WID_CL_SERVER_VISIBILITY:
1803 if (!_network_server) break;
1804
1805 ShowDropDownList(this, BuildVisibilityDropDownList(), _settings_client.network.server_game_type, WID_CL_SERVER_VISIBILITY);
1806 break;
1807
1808 case WID_CL_MATRIX: {
1809 ButtonCommon *button = this->GetButtonAtPoint(pt);
1810 if (button == nullptr) break;
1811
1812 button->OnClick(this, pt);
1813 break;
1814 }
1815 }
1816 }
1817
1818 bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
1819 {
1820 switch (widget) {
1821 case WID_CL_MATRIX: {
1822 int index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CL_MATRIX);
1823
1824 bool rtl = _current_text_dir == TD_RTL;
1825 NWidgetBase *widget_matrix = this->GetWidget<NWidgetBase>(WID_CL_MATRIX);
1826
1827 Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
1828 uint text_left = widget_matrix->pos_x + (rtl ? (uint)WD_FRAMERECT_LEFT : d.width + 8);
1829 uint text_right = widget_matrix->pos_x + widget_matrix->current_x - (rtl ? d.width + 8 : (uint)WD_FRAMERECT_RIGHT);
1830
1831 Dimension d2 = GetSpriteSize(SPR_PLAYER_SELF);
1832 uint offset_x = CLIENT_OFFSET_LEFT - d2.width - 3;
1833
1834 uint player_icon_x = rtl ? text_right - offset_x - d2.width : text_left + offset_x;
1835
1836 if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) {
1837 if (index == this->player_self_index) {
1838 GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, 0, nullptr, close_cond);
1839 return true;
1840 } else if (index == this->player_host_index) {
1841 GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, 0, nullptr, close_cond);
1842 return true;
1843 }
1844 }
1845
1846 ButtonCommon *button = this->GetButtonAtPoint(pt);
1847 if (button == nullptr) return false;
1848
1849 GuiShowTooltips(this, button->tooltip, 0, nullptr, close_cond);
1850 return true;
1851 };
1852 }
1853
1854 return false;
1855 }
1856
1857 void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
1858 {
1859 /* If you close the dropdown outside the list, don't take any action. */
1860 if (widget == WID_CL_MATRIX) return;
1861
1862 Window::OnDropdownClose(pt, widget, index, instant_close);
1863 }
1864
1865 void OnDropdownSelect(int widget, int index) override
1866 {
1867 switch (widget) {
1868 case WID_CL_SERVER_VISIBILITY:
1869 if (!_network_server) break;
1870
1871 _settings_client.network.server_game_type = (ServerGameType)index;
1872 NetworkUpdateServerGameType();
1873 break;
1874
1875 case WID_CL_MATRIX: {
1876 StringID text = STR_NULL;
1877 QueryCallbackProc *callback = nullptr;
1878
1879 switch (index) {
1880 case DD_CLIENT_ADMIN_KICK:
1881 _admin_client_id = this->dd_client_id;
1882 text = STR_NETWORK_CLIENT_LIST_ASK_CLIENT_KICK;
1883 callback = AdminClientKickCallback;
1884 SetDParamStr(0, NetworkClientInfo::GetByClientID(_admin_client_id)->client_name);
1885 break;
1886
1887 case DD_CLIENT_ADMIN_BAN:
1888 _admin_client_id = this->dd_client_id;
1889 text = STR_NETWORK_CLIENT_LIST_ASK_CLIENT_BAN;
1890 callback = AdminClientBanCallback;
1891 SetDParamStr(0, NetworkClientInfo::GetByClientID(_admin_client_id)->client_name);
1892 break;
1893
1894 case DD_COMPANY_ADMIN_RESET:
1895 _admin_company_id = this->dd_company_id;
1896 text = STR_NETWORK_CLIENT_LIST_ASK_COMPANY_RESET;
1897 callback = AdminCompanyResetCallback;
1898 SetDParam(0, _admin_company_id);
1899 break;
1900
1901 case DD_COMPANY_ADMIN_UNLOCK:
1902 _admin_company_id = this->dd_company_id;
1903 text = STR_NETWORK_CLIENT_LIST_ASK_COMPANY_UNLOCK;
1904 callback = AdminCompanyUnlockCallback;
1905 SetDParam(0, _admin_company_id);
1906 break;
1907
1908 default:
1909 NOT_REACHED();
1910 }
1911
1912 assert(text != STR_NULL);
1913 assert(callback != nullptr);
1914
1915 /* Always ask confirmation for all admin actions. */
1916 ShowQuery(STR_NETWORK_CLIENT_LIST_ASK_CAPTION, text, this, callback);
1917
1918 break;
1919 }
1920
1921 default:
1922 NOT_REACHED();
1923 }
1924
1925 this->SetDirty();
1926 }
1927
1928 void OnQueryTextFinished(char *str) override
1929 {
1930 if (str == nullptr) return;
1931
1932 switch (this->query_widget) {
1933 default: NOT_REACHED();
1934
1935 case WID_CL_SERVER_NAME_EDIT: {
1936 if (!_network_server) break;
1937
1938 SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str);
1939 this->InvalidateData();
1940 break;
1941 }
1942
1943 case WID_CL_CLIENT_NAME_EDIT: {
1944 SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), str);
1945 this->InvalidateData();
1946 break;
1947 }
1948
1949 case WID_CL_COMPANY_JOIN:
1950 NetworkClientRequestMove(this->join_company, str);
1951 break;
1952 }
1953 }
1954
1965 void DrawButtons(uint &x, uint y, const std::vector<std::unique_ptr<ButtonCommon>> &buttons) const
1966 {
1967 for (auto &button : buttons) {
1968 bool rtl = _current_text_dir == TD_RTL;
1969
1970 uint left = rtl ? x : x - button->width;
1971 uint right = rtl ? x + button->width : x;
1972
1973 int offset = std::max(0, ((int)(this->line_height + 1) - (int)button->height) / 2);
1974
1975 DrawFrameRect(left, y + offset, right, y + offset + button->height, button->colour, FR_NONE);
1976 DrawSprite(button->sprite, PAL_NONE, left + ScaleGUITrad(WD_FRAMERECT_LEFT), y + offset + ScaleGUITrad(WD_FRAMERECT_TOP));
1977 if (button->disabled) {
1978 GfxFillRect(left + 1, y + offset + 1, right - 1, y + offset + button->height - 1, _colour_gradient[button->colour & 0xF][2], FILLRECT_CHECKER);
1979 }
1980
1981 int width = button->width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
1982 x += rtl ? width : -width;
1983 }
1984 }
1985
1994 void DrawCompany(CompanyID company_id, uint left, uint right, uint top, uint &line) const
1995 {
1996 bool rtl = _current_text_dir == TD_RTL;
1997 int text_y_offset = std::max(0, ((int)(this->line_height + 1) - (int)FONT_HEIGHT_NORMAL) / 2) + WD_MATRIX_BOTTOM;
1998
1999 Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
2000 int offset = std::max(0, ((int)(this->line_height + 1) - (int)d.height) / 2);
2001
2002 uint text_left = left + (rtl ? (uint)WD_FRAMERECT_LEFT : d.width + 8);
2003 uint text_right = right - (rtl ? d.width + 8 : (uint)WD_FRAMERECT_RIGHT);
2004
2005 uint line_start = this->vscroll->GetPosition();
2006 uint line_end = line_start + this->vscroll->GetCapacity();
2007
2008 uint y = top + (this->line_height * (line - line_start));
2009
2010 /* Draw the company line (if in range of scrollbar). */
2011 if (IsInsideMM(line, line_start, line_end)) {
2012 uint x = rtl ? text_left : text_right;
2013
2014 /* If there are buttons for this company, draw them. */
2015 auto button_find = this->buttons.find(line);
2016 if (button_find != this->buttons.end()) {
2017 this->DrawButtons(x, y, button_find->second);
2018 }
2019
2020 if (company_id == COMPANY_SPECTATOR) {
2021 DrawSprite(SPR_COMPANY_ICON, PALETTE_TO_GREY, rtl ? right - d.width - 4 : left + 4, y + offset);
2022 DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_NETWORK_CLIENT_LIST_SPECTATORS, TC_SILVER);
2023 } else if (company_id == COMPANY_NEW_COMPANY) {
2024 DrawSprite(SPR_COMPANY_ICON, PALETTE_TO_GREY, rtl ? right - d.width - 4 : left + 4, y + offset);
2025 DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_NETWORK_CLIENT_LIST_NEW_COMPANY, TC_WHITE);
2026 } else {
2027 DrawCompanyIcon(company_id, rtl ? right - d.width - 4 : left + 4, y + offset);
2028
2029 SetDParam(0, company_id);
2030 SetDParam(1, company_id);
2031 DrawString(rtl ? x : text_left, rtl ? text_right : x, y + text_y_offset, STR_COMPANY_NAME, TC_SILVER);
2032 }
2033 }
2034
2035 y += this->line_height;
2036 line++;
2037
2038 for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
2039 if (ci->client_playas != company_id) continue;
2040
2041 /* Draw the player line (if in range of scrollbar). */
2042 if (IsInsideMM(line, line_start, line_end)) {
2043 uint x = rtl ? text_left : text_right;
2044
2045 /* If there are buttons for this client, draw them. */
2046 auto button_find = this->buttons.find(line);
2047 if (button_find != this->buttons.end()) {
2048 this->DrawButtons(x, y, button_find->second);
2049 }
2050
2051 SpriteID player_icon = 0;
2052 if (ci->client_id == _network_own_client_id) {
2053 player_icon = SPR_PLAYER_SELF;
2054 } else if (ci->client_id == CLIENT_ID_SERVER) {
2055 player_icon = SPR_PLAYER_HOST;
2056 }
2057
2058 if (player_icon != 0) {
2059 Dimension d2 = GetSpriteSize(player_icon);
2060 uint offset_x = CLIENT_OFFSET_LEFT - 3;
2061 int offset_y = std::max(0, ((int)(this->line_height + 1) - (int)d2.height) / 2);
2062 DrawSprite(player_icon, PALETTE_TO_GREY, rtl ? text_right - offset_x : text_left + offset_x - d2.width, y + offset_y);
2063 }
2064
2065 SetDParamStr(0, ci->client_name);
2066 DrawString(rtl ? x : text_left + CLIENT_OFFSET_LEFT, rtl ? text_right - CLIENT_OFFSET_LEFT : x, y + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK);
2067 }
2068
2069 y += this->line_height;
2070 line++;
2071 }
2072 }
2073
2074 void DrawWidget(const Rect &r, int widget) const override
2075 {
2076 switch (widget) {
2077 case WID_CL_MATRIX: {
2078 uint line = 0;
2079
2080 if (this->hover_index >= 0) {
2081 uint offset = this->hover_index * this->line_height;
2082 GfxFillRect(r.left + 2, r.top + offset, r.right - 1, r.top + offset + this->line_height - 2, GREY_SCALE(9));
2083 }
2084
2085 NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
2086 CompanyID client_playas = own_ci == nullptr ? COMPANY_SPECTATOR : own_ci->client_playas;
2087
2088 if (client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) {
2089 this->DrawCompany(COMPANY_NEW_COMPANY, r.left, r.right, r.top, line);
2090 }
2091
2092 if (client_playas != COMPANY_SPECTATOR) {
2093 this->DrawCompany(client_playas, r.left, r.right, r.top, line);
2094 }
2095
2096 for (const Company *c : Company::Iterate()) {
2097 if (client_playas == c->index) continue;
2098 this->DrawCompany(c->index, r.left, r.right, r.top, line);
2099 }
2100
2101 /* Spectators */
2102 this->DrawCompany(COMPANY_SPECTATOR, r.left, r.right, r.top, line);
2103
2104 break;
2105 }
2106 }
2107 }
2108
2109 virtual void OnMouseLoop() override
2110 {
2111 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) != WID_CL_MATRIX) {
2112 this->hover_index = -1;
2113 this->SetDirty();
2114 return;
2115 }
2116
2117 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_CL_MATRIX);
2118 int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
2119 int index = y / this->line_height;
2120
2121 if (index != this->hover_index) {
2122 this->hover_index = index;
2123 this->SetDirty();
2124 }
2125 }
2126 };
2127
2128 void ShowClientList()
2129 {
2130 AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
2131 }
2132
2133 NetworkJoinStatus _network_join_status;
2134 uint8 _network_join_waiting;
2135 uint32 _network_join_bytes;
2136 uint32 _network_join_bytes_total;
2137
2138 struct NetworkJoinStatusWindow : Window {
2139 NetworkPasswordType password_type;
2140
2141 NetworkJoinStatusWindow(WindowDesc *desc) : Window(desc)
2142 {
2143 this->parent = FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME);
2144 this->InitNested(WN_NETWORK_STATUS_WINDOW_JOIN);
2145 }
2146
2147 void DrawWidget(const Rect &r, int widget) const override
2148 {
2149 if (widget != WID_NJS_BACKGROUND) return;
2150
2151 uint8 progress; // used for progress bar
2152 DrawString(r.left + 2, r.right - 2, r.top + 20, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING, SA_HOR_CENTER);
2153 switch (_network_join_status) {
2154 case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
2155 case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
2156 progress = 10; // first two stages 10%
2157 break;
2158 case NETWORK_JOIN_STATUS_WAITING:
2159 SetDParam(0, _network_join_waiting);
2160 DrawString(r.left + 2, r.right - 2, r.top + 20 + FONT_HEIGHT_NORMAL, STR_NETWORK_CONNECTING_WAITING, TC_FROMSTRING, SA_HOR_CENTER);
2161 progress = 15; // third stage is 15%
2162 break;
2163 case NETWORK_JOIN_STATUS_DOWNLOADING:
2164 SetDParam(0, _network_join_bytes);
2165 SetDParam(1, _network_join_bytes_total);
2166 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);
2167 if (_network_join_bytes_total == 0) {
2168 progress = 15; // We don't have the final size yet; the server is still compressing!
2169 break;
2170 }
2171 FALLTHROUGH;
2172
2173 default: // Waiting is 15%, so the resting receivement of map is maximum 70%
2174 progress = 15 + _network_join_bytes * (100 - 15) / _network_join_bytes_total;
2175 }
2176
2177 /* Draw nice progress bar :) */
2178 DrawFrameRect(r.left + 20, r.top + 5, (int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
2179 }
2180
2181 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2182 {
2183 if (widget != WID_NJS_BACKGROUND) return;
2184
2185 size->height = 25 + 2 * FONT_HEIGHT_NORMAL;
2186
2187 /* Account for the statuses */
2188 uint width = 0;
2189 for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
2190 width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i).width);
2191 }
2192
2193 /* For the number of waiting (other) players */
2194 SetDParamMaxValue(0, MAX_CLIENTS);
2195 width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING).width);
2196
2197 /* Account for downloading ~ 10 MiB */
2198 SetDParamMaxDigits(0, 8);
2199 SetDParamMaxDigits(1, 8);
2200 width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1).width);
2201 width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_2).width);
2202
2203 /* Give a bit more clearing for the widest strings than strictly needed */
2204 size->width = width + WD_FRAMERECT_LEFT + WD_FRAMERECT_BOTTOM + 10;
2205 }
2206
2207 void OnClick(Point pt, int widget, int click_count) override
2208 {
2209 if (widget == WID_NJS_CANCELOK) { // Disconnect button
2210 NetworkDisconnect();
2211 SwitchToMode(SM_MENU);
2212 ShowNetworkGameWindow();
2213 }
2214 }
2215
2216 void OnQueryTextFinished(char *str) override
2217 {
2218 if (StrEmpty(str)) {
2219 NetworkDisconnect();
2220 return;
2221 }
2222
2223 switch (this->password_type) {
2224 case NETWORK_GAME_PASSWORD: MyClient::SendGamePassword (str); break;
2225 case NETWORK_COMPANY_PASSWORD: MyClient::SendCompanyPassword(str); break;
2226 default: NOT_REACHED();
2227 }
2228 }
2229 };
2230
2231 static const NWidgetPart _nested_network_join_status_window_widgets[] = {
2232 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_CONNECTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2233 NWidget(WWT_PANEL, COLOUR_GREY),
2234 NWidget(WWT_EMPTY, COLOUR_GREY, WID_NJS_BACKGROUND),
2235 NWidget(NWID_HORIZONTAL),
2236 NWidget(NWID_SPACER), SetMinimalSize(75, 0), SetFill(1, 0),
2237 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NJS_CANCELOK), SetMinimalSize(101, 12), SetDataTip(STR_NETWORK_CONNECTION_DISCONNECT, STR_NULL),
2238 NWidget(NWID_SPACER), SetMinimalSize(75, 0), SetFill(1, 0),
2239 EndContainer(),
2240 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
2241 EndContainer(),
2242 };
2243
2244 static WindowDesc _network_join_status_window_desc(
2245 WDP_CENTER, nullptr, 0, 0,
2246 WC_NETWORK_STATUS_WINDOW, WC_NONE,
2247 WDF_MODAL,
2248 _nested_network_join_status_window_widgets, lengthof(_nested_network_join_status_window_widgets)
2249 );
2250
2251 void ShowJoinStatusWindow()
2252 {
2253 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
2254 new NetworkJoinStatusWindow(&_network_join_status_window_desc);
2255 }
2256
2257 void ShowNetworkNeedPassword(NetworkPasswordType npt)
2258 {
2259 NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
2260 if (w == nullptr) return;
2261 w->password_type = npt;
2262
2263 StringID caption;
2264 switch (npt) {
2265 default: NOT_REACHED();
2266 case NETWORK_GAME_PASSWORD: caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
2267 case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
2268 }
2269 ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_PASSWORD);
2270 }
2271
2272 struct NetworkCompanyPasswordWindow : public Window {
2273 QueryString password_editbox;
2274 Dimension warning_size;
2275
2276 NetworkCompanyPasswordWindow(WindowDesc *desc, Window *parent) : Window(desc), password_editbox(lengthof(_settings_client.network.default_company_pass))
2277 {
2278 this->InitNested(0);
2279 this->UpdateWarningStringSize();
2280
2281 this->parent = parent;
2282 this->querystrings[WID_NCP_PASSWORD] = &this->password_editbox;
2283 this->password_editbox.cancel_button = WID_NCP_CANCEL;
2284 this->password_editbox.ok_button = WID_NCP_OK;
2285 this->SetFocusedWidget(WID_NCP_PASSWORD);
2286 }
2287
2288 void UpdateWarningStringSize()
2289 {
2290 assert(this->nested_root->smallest_x > 0);
2291 this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT);
2292 this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width);
2293 this->warning_size.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
2294
2295 this->ReInit();
2296 }
2297
2298 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2299 {
2300 if (widget == WID_NCP_WARNING) {
2301 *size = this->warning_size;
2302 }
2303 }
2304
2305 void DrawWidget(const Rect &r, int widget) const override
2306 {
2307 if (widget != WID_NCP_WARNING) return;
2308
2309 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT,
2310 r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
2311 STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER);
2312 }
2313
2314 void OnOk()
2315 {
2316 if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
2317 _settings_client.network.default_company_pass = this->password_editbox.text.buf;
2318 }
2319
2320 NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf);
2321 }
2322
2323 void OnClick(Point pt, int widget, int click_count) override
2324 {
2325 switch (widget) {
2326 case WID_NCP_OK:
2327 this->OnOk();
2328 FALLTHROUGH;
2329
2330 case WID_NCP_CANCEL:
2331 this->Close();
2332 break;
2333
2334 case WID_NCP_SAVE_AS_DEFAULT_PASSWORD:
2335 this->ToggleWidgetLoweredState(WID_NCP_SAVE_AS_DEFAULT_PASSWORD);
2336 this->SetDirty();
2337 break;
2338 }
2339 }
2340 };
2341
2342 static const NWidgetPart _nested_network_company_password_window_widgets[] = {
2343 NWidget(NWID_HORIZONTAL),
2344 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2345 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_PASSWORD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2346 EndContainer(),
2347 NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_BACKGROUND),
2348 NWidget(NWID_VERTICAL), SetPIP(5, 5, 5),
2349 NWidget(NWID_HORIZONTAL), SetPIP(5, 5, 5),
2350 NWidget(WWT_TEXT, COLOUR_GREY, WID_NCP_LABEL), SetDataTip(STR_COMPANY_VIEW_PASSWORD, STR_NULL),
2351 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NCP_PASSWORD), SetFill(1, 0), SetMinimalSize(194, 12), SetDataTip(STR_COMPANY_VIEW_SET_PASSWORD, STR_NULL),
2352 EndContainer(),
2353 NWidget(NWID_HORIZONTAL), SetPIP(5, 0, 5),
2354 NWidget(NWID_SPACER), SetFill(1, 0),
2355 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_NCP_SAVE_AS_DEFAULT_PASSWORD), SetMinimalSize(194, 12),
2356 SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
2357 EndContainer(),
2358 EndContainer(),
2359 EndContainer(),
2360 NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_WARNING), EndContainer(),
2361 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
2362 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL),
2363 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK),
2364 EndContainer(),
2365 };
2366
2367 static WindowDesc _network_company_password_window_desc(
2368 WDP_AUTO, nullptr, 0, 0,
2369 WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
2370 0,
2371 _nested_network_company_password_window_widgets, lengthof(_nested_network_company_password_window_widgets)
2372 );
2373
2374 void ShowNetworkCompanyPasswordWindow(Window *parent)
2375 {
2376 CloseWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
2377
2378 new NetworkCompanyPasswordWindow(&_network_company_password_window_desc, parent);
2379 }
2380
2384 struct NetworkAskRelayWindow : public Window {
2385 std::string server_connection_string;
2386 std::string relay_connection_string;
2387 std::string token;
2388
2389 NetworkAskRelayWindow(WindowDesc *desc, Window *parent, const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token) :
2390 Window(desc),
2391 server_connection_string(server_connection_string),
2392 relay_connection_string(relay_connection_string),
2393 token(token)
2394 {
2395 this->parent = parent;
2396 this->InitNested(0);
2397 }
2398
2399 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2400 {
2401 if (widget == WID_NAR_TEXT) {
2402 *size = GetStringBoundingBox(STR_NETWORK_ASK_RELAY_TEXT);
2403 size->height = GetStringHeight(STR_NETWORK_ASK_RELAY_TEXT, size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT) + WD_FRAMETEXT_BOTTOM + WD_FRAMETEXT_TOP;
2404 }
2405 }
2406
2407 void DrawWidget(const Rect &r, int widget) const override
2408 {
2409 if (widget == WID_NAR_TEXT) {
2410 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMETEXT_BOTTOM, STR_NETWORK_ASK_RELAY_TEXT, TC_FROMSTRING, SA_CENTER);
2411 }
2412 }
2413
2414 void FindWindowPlacementAndResize(int def_width, int def_height) override
2415 {
2416 /* Position query window over the calling window, ensuring it's within screen bounds. */
2417 this->left = Clamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width);
2418 this->top = Clamp(parent->top + (parent->height / 2) - (this->height / 2), 0, _screen.height - this->height);
2419 this->SetDirty();
2420 }
2421
2422 void SetStringParameters(int widget) const override
2423 {
2424 switch (widget) {
2425 case WID_NAR_TEXT:
2426 SetDParamStr(0, this->server_connection_string);
2427 SetDParamStr(1, this->relay_connection_string);
2428 break;
2429 }
2430 }
2431
2432 void OnClick(Point pt, int widget, int click_count) override
2433 {
2434 switch (widget) {
2435 case WID_NAR_NO:
2436 _network_coordinator_client.ConnectFailure(this->token, 0);
2437 this->Close();
2438 break;
2439
2440 case WID_NAR_YES_ONCE:
2441 _network_coordinator_client.StartTurnConnection(this->token);
2442 this->Close();
2443 break;
2444
2445 case WID_NAR_YES_ALWAYS:
2446 _settings_client.network.use_relay_service = URS_ALLOW;
2447 _network_coordinator_client.StartTurnConnection(this->token);
2448 this->Close();
2449 break;
2450 }
2451 }
2452 };
2453
2454 static const NWidgetPart _nested_network_ask_relay_widgets[] = {
2455 NWidget(NWID_HORIZONTAL),
2456 NWidget(WWT_CLOSEBOX, COLOUR_RED),
2457 NWidget(WWT_CAPTION, COLOUR_RED, WID_NAR_CAPTION), SetDataTip(STR_NETWORK_ASK_RELAY_CAPTION, STR_NULL),
2458 EndContainer(),
2459 NWidget(WWT_PANEL, COLOUR_RED), SetPIP(0, 0, 8),
2460 NWidget(WWT_TEXT, COLOUR_RED, WID_NAR_TEXT), SetAlignment(SA_HOR_CENTER), SetFill(1, 1),
2461 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 15, 10),
2462 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_NO, STR_NULL),
2463 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ONCE), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ONCE, STR_NULL),
2464 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ALWAYS), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ALWAYS, STR_NULL),
2465 EndContainer(),
2466 EndContainer(),
2467 };
2468
2469 static WindowDesc _network_ask_relay_desc(
2470 WDP_CENTER, nullptr, 0, 0,
2471 WC_NETWORK_ASK_RELAY, WC_NONE,
2472 WDF_MODAL,
2473 _nested_network_ask_relay_widgets, lengthof(_nested_network_ask_relay_widgets)
2474 );
2475
2482 void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
2483 {
2484 CloseWindowByClass(WC_NETWORK_ASK_RELAY);
2485
2486 Window *parent = FindWindowById(WC_MAIN_WINDOW, 0);
2487 new NetworkAskRelayWindow(&_network_ask_relay_desc, parent, server_connection_string, relay_connection_string, token);
2488 }
NWidgetServerListHeader::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: network_gui.cpp:191
ShowNewGRFSettings
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
Definition: newgrf_gui.cpp:1995
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
network_content.h
WID_CL_MATRIX
@ WID_CL_MATRIX
Company/client list.
Definition: network_widget.h:89
NetworkSettings::connect_to_ip
std::string connect_to_ip
default for the "Add server" query
Definition: settings_type.h:287
NetworkGameWindow::NGameAllowedSorter
static bool NGameAllowedSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by joinability.
Definition: network_gui.cpp:344
NetworkServerGameInfo::gamescript_version
int gamescript_version
Version of the gamescript.
Definition: game_info.h:109
_admin_client_id
static ClientID _admin_client_id
For what client a confirmation window is open.
Definition: network_gui.cpp:59
NetworkClientListWindow::OnClickClientAdmin
static void OnClickClientAdmin(NetworkClientListWindow *w, Point pt, ClientID client_id)
Admin button on a Client is clicked.
Definition: network_gui.cpp:1550
NetworkValidateServerName
bool NetworkValidateServerName(std::string &server_name)
Trim the given server name in place, i.e.
Definition: network.cpp:830
NetworkGameList::connection_string
std::string connection_string
Address of the server.
Definition: network_gamelist.h:31
_network_join_bytes_total
uint32 _network_join_bytes_total
The total number of bytes to download.
Definition: network_gui.cpp:2136
AdminCompanyUnlockCallback
static void AdminCompanyUnlockCallback(Window *w, bool confirmed)
Callback function for admin command to unlock company.
Definition: network_gui.cpp:1407
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
NetworkGameWindow::name_editbox
QueryString name_editbox
Client name editbox.
Definition: network_gui.cpp:230
InvalidateWindowData
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-...
Definition: window.cpp:3234
NetworkServerGameInfo::gamescript_name
std::string gamescript_name
Name of the gamescript.
Definition: game_info.h:110
WID_NSS_CLIENTS_TXT
@ WID_NSS_CLIENTS_TXT
'Max clients' text.
Definition: network_widget.h:63
WID_NG_REFRESH
@ WID_NG_REFRESH
'Refresh server' button.
Definition: network_widget.h:40
NetworkGameWindow
Definition: network_gui.cpp:216
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1239
WID_NSS_CANCEL
@ WID_NSS_CANCEL
'Cancel' button.
Definition: network_widget.h:75
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition: fileio_type.h:19
ClientNetworkCoordinatorSocketHandler::ConnectFailure
void ConnectFailure(const std::string &token, uint8 tracking_number)
Callback from a Connecter to let the Game Coordinator know the connection failed.
Definition: network_coordinator.cpp:545
WID_NSS_GAMENAME
@ WID_NSS_GAMENAME
Background for editbox to set game name.
Definition: network_widget.h:57
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
NWidgetServerListHeader::MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER
static const uint MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER
Minimum width before adding a new header.
Definition: network_gui.cpp:88
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
Window::timeout_timer
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:309
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
NetworkAskRelayWindow::relay_connection_string
std::string relay_connection_string
The relay server we want to connect to.
Definition: network_gui.cpp:2386
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
NetworkValidateOurClientName
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
Definition: network_client.cpp:1256
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
NetworkAddServer
NetworkGameList * NetworkAddServer(const std::string &connection_string, bool manually, bool never_expire)
Validates an address entered as a string and adds the server to the list.
Definition: network.cpp:673
QSF_PASSWORD
@ QSF_PASSWORD
password entry box, show warning about password security
Definition: textbuf_gui.h:23
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:662
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:670
Window::nested_root
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:324
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1139
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
NetworkServerGameInfo::game_date
Date game_date
Current date.
Definition: game_info.h:96
WID_CL_SERVER_VISIBILITY
@ WID_CL_SERVER_VISIBILITY
Server visibility.
Definition: network_widget.h:84
NetworkGameWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:515
NetworkGameWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: network_gui.cpp:878
_network_join_waiting
uint8 _network_join_waiting
The number of clients waiting in front of us.
Definition: network_gui.cpp:2134
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
GetSettingFromName
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
Definition: settings.cpp:1419
NetworkGameWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar of the list of servers.
Definition: network_gui.cpp:229
_network_server_connection_type
ConnectionType _network_server_connection_type
What type of connection the Game Coordinator detected we are on.
Definition: network_coordinator.cpp:31
NetworkClientListWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:1725
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
NetworkSettings::max_clients
uint8 max_clients
maximum amount of clients
Definition: settings_type.h:294
NetworkClientListWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: network_gui.cpp:1865
NetworkClientListWindow::GetButtonAtPoint
ButtonCommon * GetButtonAtPoint(Point pt)
Get the button at a specific point on the WID_CL_MATRIX.
Definition: network_gui.cpp:1675
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1004
WID_NG_NEWGRF_MISSING
@ WID_NG_NEWGRF_MISSING
'Find missing NewGRF online' button.
Definition: network_widget.h:43
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1047
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
NETWORK_NAME_LENGTH
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
Definition: config.h:55
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:80
NetworkStartServerWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:1067
ClientListWidgets
ClientListWidgets
Widgets of the NetworkClientListWindow class.
Definition: network_widget.h:79
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:775
NetworkServerGameInfo::server_revision
std::string server_revision
The version number the server is using (e.g.: 'r304' or 0.5.0)
Definition: game_info.h:100
WID_NAR_TEXT
@ WID_NAR_TEXT
Text in the window.
Definition: network_widget.h:115
WID_NSS_GAMENAME_LABEL
@ WID_NSS_GAMENAME_LABEL
Label for the game name.
Definition: network_widget.h:56
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company_id, const std::string &pass)
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1187
NetworkGameWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: network_gui.cpp:820
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
NetworkSettings::default_company_pass
std::string default_company_pass
default password for new companies in encrypted form
Definition: settings_type.h:286
NetworkGameWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_gui.cpp:814
GUIList< NetworkGameList *, StringFilter & >
WID_NJS_CANCELOK
@ WID_NJS_CANCELOK
Cancel / OK button.
Definition: network_widget.h:98
_network_server
bool _network_server
network-server is active
Definition: network.cpp:58
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
Button::id
T id
ID this button belongs to.
Definition: network_gui.cpp:1453
NetworkGameWidgets
NetworkGameWidgets
Widgets of the NetworkGameWindow class.
Definition: network_widget.h:14
NetworkGameWindow::SortNetworkGameList
void SortNetworkGameList()
Sort the server list.
Definition: network_gui.cpp:361
NetworkClientListWindow::hover_index
int hover_index
Index of the current line we are hovering over, or -1 if none.
Definition: network_gui.cpp:1490
NETWORK_LIST_REFRESH_DELAY
static const int NETWORK_LIST_REFRESH_DELAY
Time, in seconds, between updates of the network list.
Definition: network_gui.cpp:57
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
WID_NG_CANCEL
@ WID_NG_CANCEL
'Cancel' button.
Definition: network_widget.h:50
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition: window_type.h:470
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
NetworkServerGameInfo::clients_max
byte clients_max
Max clients allowed on server.
Definition: game_info.h:104
WC_COMPANY_PASSWORD_WINDOW
@ WC_COMPANY_PASSWORD_WINDOW
Company password query; Window numbers:
Definition: window_type.h:495
NetworkCompanyHasClients
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
Definition: network_server.cpp:2019
NetworkClientListWindow::OnClickCompanyJoin
static void OnClickCompanyJoin(NetworkClientListWindow *w, Point pt, CompanyID company_id)
Join button on a Company is clicked.
Definition: network_gui.cpp:1515
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
NetworkGameWindow::servers
GUIGameServerList servers
List with game servers.
Definition: network_gui.cpp:227
NetworkJoinStatus
NetworkJoinStatus
Status of the clients during joining.
Definition: network_internal.h:54
NetworkClientListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: network_gui.cpp:1748
WID_NG_LASTJOINED_LABEL
@ WID_NG_LASTJOINED_LABEL
Label "Last joined server:".
Definition: network_widget.h:33
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WID_NAR_YES_ONCE
@ WID_NAR_YES_ONCE
"Yes, once" button.
Definition: network_widget.h:117
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
NetworkCompanyPasswordWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:2305
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1146
NetworkGameWindow::NGameNameSorter
static bool NGameNameSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by name.
Definition: network_gui.cpp:292
WID_NSS_COMPANIES_BTND
@ WID_NSS_COMPANIES_BTND
'Max companies' downarrow.
Definition: network_widget.h:66
NetworkClientListWindow::buttons
std::map< uint, std::vector< std::unique_ptr< ButtonCommon > > > buttons
Per line which buttons are available.
Definition: network_gui.cpp:1494
ShowMissingContentWindow
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
Definition: newgrf_gui.cpp:1543
AdminCompanyResetCallback
static void AdminCompanyResetCallback(Window *w, bool confirmed)
Callback function for admin command to reset company.
Definition: network_gui.cpp:1394
NetworkServerDoMove
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
Definition: network_server.cpp:1912
Button
Template version of Button, with callback support.
Definition: network_gui.cpp:1450
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:710
NetworkCompanyPasswordWindow::password_editbox
QueryString password_editbox
Password editbox.
Definition: network_gui.cpp:2273
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
NetworkAskRelayWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:2407
MAX_CLIENTS
static const uint MAX_CLIENTS
How many clients can we have.
Definition: network_type.h:14
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
WID_CL_CLIENT_COMPANY_COUNT
@ WID_CL_CLIENT_COMPANY_COUNT
Count of clients and companies.
Definition: network_widget.h:92
NetworkJoinStatusWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:2147
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:815
NetworkGameWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: network_gui.cpp:850
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
WID_NSS_BACKGROUND
@ WID_NSS_BACKGROUND
Background of the window.
Definition: network_widget.h:55
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:91
ButtonCommon::colour
Colours colour
The colour of the button.
Definition: network_gui.cpp:1423
WID_NG_NEWGRF_MISSING_SEL
@ WID_NG_NEWGRF_MISSING_SEL
Selection widget for the above button.
Definition: network_widget.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
DrawString
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.
Definition: gfx.cpp:643
UpdateNetworkGameWindow
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Definition: network_gui.cpp:66
NetworkUDPSearchGame
void NetworkUDPSearchGame()
Find all servers.
Definition: network_udp.cpp:113
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:422
WID_NG_FILTER
@ WID_NG_FILTER
Panel with the edit box to enter the search text.
Definition: network_widget.h:20
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
WID_CL_SERVER_NAME_EDIT
@ WID_CL_SERVER_NAME_EDIT
Edit button for server name.
Definition: network_widget.h:83
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
network_gui.h
NetworkClientListWindow::dd_client_id
ClientID dd_client_id
During admin dropdown, track which client this was for.
Definition: network_gui.cpp:1484
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:293
NetworkCompanyPasswordWindow
Definition: network_gui.cpp:2272
_network_join_status
NetworkJoinStatus _network_join_status
The status of joining.
Definition: network_gui.cpp:2133
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
_network_server_name
std::string _network_server_name
The current name of the server you are on.
Definition: network_client.cpp:317
WID_NG_MAPSIZE
@ WID_NG_MAPSIZE
'Map size' button.
Definition: network_widget.h:25
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:334
NetworkSettings::use_relay_service
UseRelayService use_relay_service
Use relay service?
Definition: settings_type.h:300
NetworkGameWindow::NGameClientSorter
static bool NGameClientSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the amount of clients online on a server.
Definition: network_gui.cpp:305
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2098
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:646
NETWORK_CLIENT_NAME_LENGTH
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
Definition: config.h:63
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:184
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:629
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
AdminClientKickCallback
static void AdminClientKickCallback(Window *w, bool confirmed)
Callback function for admin command to kick client.
Definition: network_gui.cpp:1374
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
NetworkGameInfo::version_compatible
bool version_compatible
Can we connect to this server or not? (based on server_revision)
Definition: game_info.h:118
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1799
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NetworkSendCommand
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company)
Prepare a DoCommand to be send over the network.
Definition: network_command.cpp:136
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
GENERATE_NEW_SEED
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:24
NetworkStartServerWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_gui.cpp:1039
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
Button::OnClick
void OnClick(struct NetworkClientListWindow *w, Point pt) override
OnClick handler for when the button is pressed.
Definition: network_gui.cpp:1465
WID_NCP_SAVE_AS_DEFAULT_PASSWORD
@ WID_NCP_SAVE_AS_DEFAULT_PASSWORD
Toggle 'button' for saving the current password as default password.
Definition: network_widget.h:106
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:889
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
network_base.h
WID_NSS_CLIENTS_BTNU
@ WID_NSS_CLIENTS_BTNU
'Max clients' uparrow.
Definition: network_widget.h:64
NWidgetServerListHeader
Full blown container to make it behave exactly as we want :)
Definition: network_gui.cpp:87
DrawStringMultiLine
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.
Definition: gfx.cpp:788
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
WID_NG_SCROLLBAR
@ WID_NG_SCROLLBAR
Scrollbar of matrix.
Definition: network_widget.h:31
_network_game_list
NetworkGameList * _network_game_list
Game list of this client.
Definition: network_gamelist.cpp:23
WID_NG_MAIN
@ WID_NG_MAIN
Main panel.
Definition: network_widget.h:15
NetworkClientListWindow::dd_company_id
CompanyID dd_company_id
During admin dropdown, track which company this was for.
Definition: network_gui.cpp:1485
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
NetworkChangeCompanyPassword
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
Definition: network.cpp:156
NetworkQueryServer
void NetworkQueryServer(const std::string &connection_string)
Query a server to fetch the game-info.
Definition: network.cpp:653
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NetworkClientListWindow::OnClickCompanyAdmin
static void OnClickCompanyAdmin(NetworkClientListWindow *w, Point pt, CompanyID company_id)
Admin button on a Company is clicked.
Definition: network_gui.cpp:1572
NWidgetBase::prev
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:193
WID_NSS_PLAY_SCENARIO
@ WID_NSS_PLAY_SCENARIO
Play scenario button.
Definition: network_widget.h:72
NetworkGameWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: network_gui.cpp:883
WID_NSS_CONNTYPE_BTN
@ WID_NSS_CONNTYPE_BTN
'Connection type' droplist button.
Definition: network_widget.h:60
WindowDesc
High level window description.
Definition: window_gui.h:168
network_coordinator.h
NetworkJoinStatusWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:2207
NetworkAskRelayWindow
Window used for asking the user if he is okay using a relay server.
Definition: network_gui.cpp:2384
WID_NG_CLIENTS
@ WID_NG_CLIENTS
'Clients' button.
Definition: network_widget.h:24
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:113
NetworkGameWindow::last_joined
NetworkGameList * last_joined
The last joined server.
Definition: network_gui.cpp:226
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:463
WID_CL_SCROLLBAR
@ WID_CL_SCROLLBAR
Scrollbar for company/client list.
Definition: network_widget.h:90
WID_NG_ADD
@ WID_NG_ADD
'Add server' button.
Definition: network_widget.h:48
NWidgetServerListHeader::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: network_gui.cpp:141
ClientNetworkGameSocketHandler::SendCompanyPassword
static NetworkRecvStatus SendCompanyPassword(const std::string &password)
Set the company password as requested.
Definition: network_client.cpp:371
GUITimer
Definition: guitimer_func.h:13
NGLS_TOO_OLD
@ NGLS_TOO_OLD
Server is too old to query.
Definition: network_gamelist.h:23
WID_CL_SERVER_NAME
@ WID_CL_SERVER_NAME
Server name.
Definition: network_widget.h:82
NetworkClientListWindow::OnTooltip
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition: network_gui.cpp:1818
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:34
NetworkClientListWindow::DrawButtons
void DrawButtons(uint &x, uint y, const std::vector< std::unique_ptr< ButtonCommon >> &buttons) const
Draw the buttons for a single line in the matrix.
Definition: network_gui.cpp:1965
WID_NSS_COMPANIES_BTNU
@ WID_NSS_COMPANIES_BTNU
'Max companies' uparrow.
Definition: network_widget.h:68
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
NetworkStartServerWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: network_gui.cpp:1187
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition: fileio_type.h:49
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition: misc_gui.cpp:768
NetworkSettings::last_joined
std::string last_joined
Last joined server.
Definition: settings_type.h:298
NetworkClientListWindow::OnClickClientChat
static void OnClickClientChat(NetworkClientListWindow *w, Point pt, ClientID client_id)
Chat button on a Client is clicked.
Definition: network_gui.cpp:1593
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
NetworkClientListWindow
Main handle for clientlist.
Definition: network_gui.cpp:1479
Button::ButtonCallback
void(* ButtonCallback)(struct NetworkClientListWindow *w, Point pt, T id)
Callback function to call on click.
Definition: network_gui.cpp:1452
NWidgetContainer::tail
NWidgetBase * tail
Pointer to last widget in container.
Definition: widget_type.h:416
ShowGenerateLandscape
void ShowGenerateLandscape()
Start with a normal game.
Definition: genworld_gui.cpp:1000
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
NetworkMaxCompaniesReached
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
Definition: network_client.cpp:1329
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
NWidgetServerListHeader::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: network_gui.cpp:115
NetworkStartServerWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: network_gui.cpp:1154
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
WN_NETWORK_WINDOW_START
@ WN_NETWORK_WINDOW_START
Network start server.
Definition: window_type.h:29
NetworkClientListWindow::OnClickCompanyNew
static void OnClickCompanyNew(NetworkClientListWindow *w, Point pt, CompanyID company_id)
Crete new company button is clicked.
Definition: network_gui.cpp:1535
NetworkStartServerWindow::name_editbox
QueryString name_editbox
Server name editbox.
Definition: network_gui.cpp:1027
GUIList< NetworkGameList *, StringFilter & >::SortFunction
bool SortFunction(const NetworkGameList * &, const NetworkGameList * &)
Signature of sort function.
Definition: sortlist_type.h:48
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:916
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:183
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
NetworkGameWindow::NGameDateSorter
static bool NGameDateSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by current date.
Definition: network_gui.cpp:327
IsInsideBS
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.
Definition: math_func.hpp:188
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:47
WID_NCP_WARNING
@ WID_NCP_WARNING
Warning text about password security.
Definition: network_widget.h:107
WD_PAR_VSEP_NORMAL
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:139
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
NetworkAskRelayWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:2399
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WID_NAR_YES_ALWAYS
@ WID_NAR_YES_ALWAYS
"Yes, always" button.
Definition: network_widget.h:118
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
WID_NG_MATRIX
@ WID_NG_MATRIX
Panel with list of games.
Definition: network_widget.h:30
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
NetworkGameWindow::filter_editbox
QueryString filter_editbox
Editbox for filter on servers.
Definition: network_gui.cpp:231
NetworkGameWindow::NGameYearsSorter
static bool NGameYearsSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the number of days the game is running.
Definition: network_gui.cpp:334
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:443
NetworkGameWindow::requery_timer
GUITimer requery_timer
Timer for network requery.
Definition: network_gui.cpp:232
GetWidgetFromPos
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:194
WID_NG_HEADER
@ WID_NG_HEADER
Header container of the matrix.
Definition: network_widget.h:22
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1125
Scrollbar::UpdateListPositionOnKeyPress
EventState UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition: widget.cpp:2119
StrStartsWith
bool StrStartsWith(const std::string_view str, const std::string_view prefix)
Check whether the given string starts with the given prefix.
Definition: string.cpp:367
CCA_NEW
@ CCA_NEW
Create a new company.
Definition: company_type.h:65
WID_NSS_CONNTYPE_LABEL
@ WID_NSS_CONNTYPE_LABEL
Label for 'connection type'.
Definition: network_widget.h:59
WID_NSS_GENERATE_GAME
@ WID_NSS_GENERATE_GAME
New game button.
Definition: network_widget.h:70
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
WID_NG_NEWGRF
@ WID_NG_NEWGRF
'NewGRF Settings' button.
Definition: network_widget.h:41
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
WID_NG_CLIENT
@ WID_NG_CLIENT
Panel with editbox to set client name.
Definition: network_widget.h:18
NetworkCompanyPasswordWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:2323
NetworkClientListWindow::line_count
uint line_count
Amount of lines in the matrix.
Definition: network_gui.cpp:1489
WID_NJS_BACKGROUND
@ WID_NJS_BACKGROUND
Background of the window.
Definition: network_widget.h:97
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
NETWORK_COMPANY_PASSWORD
@ NETWORK_COMPANY_PASSWORD
The password of the company.
Definition: network_type.h:82
NetworkDisconnect
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
Definition: network.cpp:944
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1119
NetworkSettings::client_name
std::string client_name
name of the player (as client)
Definition: settings_type.h:285
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
WID_NCP_CANCEL
@ WID_NCP_CANCEL
Close the window without changing anything.
Definition: network_widget.h:108
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
NWidgetServerListHeader::IsWidgetVisible
bool IsWidgetVisible(NetworkGameWidgets widget) const
Checks whether the given widget is actually visible.
Definition: network_gui.cpp:209
WF_TIMEOUT
@ WF_TIMEOUT
Window timeout counter.
Definition: window_gui.h:234
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition: network_type.h:49
WN_NETWORK_WINDOW_GAME
@ WN_NETWORK_WINDOW_GAME
Network game window.
Definition: window_type.h:27
WID_NCP_LABEL
@ WID_NCP_LABEL
Label in front of the password field.
Definition: network_widget.h:104
NetworkGameWindow::blot_offset
int blot_offset
Left offset for green/yellow/red compatibility icon.
Definition: network_gui.cpp:236
Button::proc
ButtonCallback proc
Callback proc to call when button is pressed.
Definition: network_gui.cpp:1454
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:64
NetworkClientListWindow::OnClickCompanyChat
static void OnClickCompanyChat(NetworkClientListWindow *w, Point pt, CompanyID company_id)
Chat button on a Company is clicked.
Definition: network_gui.cpp:1504
WID_NAR_NO
@ WID_NAR_NO
"No" button.
Definition: network_widget.h:116
NetworkGameWindow::BuildGUINetworkGameList
void BuildGUINetworkGameList()
(Re)build the GUI network game list (a.k.a.
Definition: network_gui.cpp:244
NetworkStartServerWindow::widget_id
byte widget_id
The widget that has the pop-up input menu.
Definition: network_gui.cpp:1026
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1042
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:211
NetworkServerGameInfo::companies_on
byte companies_on
How many started companies do we have.
Definition: game_info.h:105
NetworkServerKickOrBanIP
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
Definition: network_server.cpp:1970
network_client.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
NetworkGameWindow::searched_internet
bool searched_internet
Did we ever press "Search Internet" button?
Definition: network_gui.cpp:233
NetworkServerGameInfo::companies_max
byte companies_max
Max companies allowed on server.
Definition: game_info.h:106
ClientNetworkCoordinatorSocketHandler::GetListing
void GetListing()
Request a listing of all public servers.
Definition: network_coordinator.cpp:495
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
NetworkAskRelayWindow::token
std::string token
The token for this connection.
Definition: network_gui.cpp:2387
NetworkClientListWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: network_gui.cpp:1857
NWidgetContainer::head
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:415
NetworkStartServerWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:1056
NetworkClientListWindow::player_self_index
int player_self_index
The line the current player is on.
Definition: network_gui.cpp:1491
network_server.h
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition: company_type.h:56
WID_CL_CLIENT_NAME_EDIT
@ WID_CL_CLIENT_NAME_EDIT
Edit button for client name.
Definition: network_widget.h:88
WID_NG_YEARS
@ WID_NG_YEARS
'Years' button.
Definition: network_widget.h:27
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:506
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:921
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition: fileio_type.h:18
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
GfxFillRect
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.
Definition: gfx.cpp:117
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:233
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3174
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
NetworkStartServerWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: network_gui.cpp:1176
NetworkCompanyIsPassworded
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:212
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:187
WID_NSS_PLAY_HEIGHTMAP
@ WID_NSS_PLAY_HEIGHTMAP
Play heightmap button.
Definition: network_widget.h:73
StartNewGameWithoutGUI
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
Definition: genworld_gui.cpp:1021
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
NetworkClientListWindow::player_host_index
int player_host_index
The line the host is on.
Definition: network_gui.cpp:1492
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
NETWORK_HOSTNAME_PORT_LENGTH
static const uint NETWORK_HOSTNAME_PORT_LENGTH
The maximum length of the host name + port, in bytes including '\0'. The extra six is ":" + port numb...
Definition: config.h:58
CONNECTION_TYPE_UNKNOWN
@ CONNECTION_TYPE_UNKNOWN
The Game Coordinator hasn't informed us yet what type of connection we have.
Definition: tcp_coordinator.h:53
WID_NG_DATE
@ WID_NG_DATE
'Date' button.
Definition: network_widget.h:26
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:194
NETWORK_PASSWORD_LENGTH
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
Definition: config.h:61
NWidgetBase::next
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:192
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
Window::nested_array
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:325
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:905
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:714
NetworkGameWindow::DrawServerLine
void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
Draw a single server line.
Definition: network_gui.cpp:394
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:977
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
ButtonCommon::tooltip
StringID tooltip
The tooltip of the button.
Definition: network_gui.cpp:1422
NetworkSettings::server_name
std::string server_name
name of the server
Definition: settings_type.h:281
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
NetworkAskRelayWindow::server_connection_string
std::string server_connection_string
The game server we want to connect to.
Definition: network_gui.cpp:2385
WID_CL_SERVER_SELECTOR
@ WID_CL_SERVER_SELECTOR
Selector to hide the server frame.
Definition: network_widget.h:81
WID_NG_INFO
@ WID_NG_INFO
Third button in the game list panel.
Definition: network_widget.h:28
WID_NSS_CLIENTS_LABEL
@ WID_NSS_CLIENTS_LABEL
Label for 'max clients'.
Definition: network_widget.h:61
NetworkClientListWindow::join_company
CompanyID join_company
During query for company password, this stores what company we wanted to join.
Definition: network_gui.cpp:1482
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:105
NetworkJoinStatusWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:2181
NetworkGameWindow::ScrollToSelectedServer
void ScrollToSelectedServer()
Scroll the list up or down to the currently selected server.
Definition: network_gui.cpp:464
WID_NCP_BACKGROUND
@ WID_NCP_BACKGROUND
Background of the window.
Definition: network_widget.h:103
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NetworkGameWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:561
NetworkGameWindow::server
NetworkGameList * server
Selected server.
Definition: network_gui.cpp:225
WID_NG_NEWGRF_SEL
@ WID_NG_NEWGRF_SEL
Selection 'widget' to hide the NewGRF settings.
Definition: network_widget.h:42
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:177
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1268
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
NetworkSettings::server_game_type
ServerGameType server_game_type
Server type: local / public / invite-only.
Definition: settings_type.h:278
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
WID_NG_SEARCH_LAN
@ WID_NG_SEARCH_LAN
'Search LAN server' button.
Definition: network_widget.h:47
WID_NG_LASTJOINED
@ WID_NG_LASTJOINED
Info about the last joined server.
Definition: network_widget.h:34
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
DropDownAdmin
DropDownAdmin
The possibly entries in a DropDown for an admin.
Definition: network_gui.cpp:1362
Pool::PoolItem<&_networkclientinfo_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_admin_company_id
static CompanyID _admin_company_id
For what company a confirmation window is open.
Definition: network_gui.cpp:60
ServerGameType
ServerGameType
Game type the server can be using.
Definition: network_type.h:40
NetworkStartServerWindow
Definition: network_gui.cpp:1025
NetworkAskRelayWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:2432
WID_CL_SERVER_INVITE_CODE
@ WID_CL_SERVER_INVITE_CODE
Invite code for this server.
Definition: network_widget.h:85
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
Pool::PoolItem<&_networkclientinfo_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:367
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
NetworkServerGameInfo::map_width
uint16 map_width
Map width.
Definition: game_info.h:97
NetworkClientListWindow::RebuildListCompany
void RebuildListCompany(CompanyID company_id, CompanyID client_playas)
Part of RebuildList() to create the information for a single company.
Definition: network_gui.cpp:1603
network_udp.h
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
NetworkStartServerWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:1076
NetworkClientListWindow::line_height
uint line_height
Current lineheight of each entry in the matrix.
Definition: network_gui.cpp:1488
WID_NCP_PASSWORD
@ WID_NCP_PASSWORD
Input field for the password.
Definition: network_widget.h:105
SetSettingValue
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1551
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:167
NetworkClientListWindow::DrawCompany
void DrawCompany(CompanyID company_id, uint left, uint right, uint top, uint &line) const
Draw a company and its clients on the matrix.
Definition: network_gui.cpp:1994
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
NetworkClientListWindow::query_widget
ClientListWidgets query_widget
During a query this tracks what widget caused the query.
Definition: network_gui.cpp:1481
PC_DARK_BLUE
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
Definition: gfx_func.h:212
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:176
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:464
GUIList< NetworkGameList *, StringFilter & >::FilterFunction
bool CDECL FilterFunction(const NetworkGameList * *, StringFilter &)
Signature of filter function.
Definition: sortlist_type.h:49
WID_NG_SEARCH_INTERNET
@ WID_NG_SEARCH_INTERNET
'Search internet server' button.
Definition: network_widget.h:46
SetDParamMaxValue
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.
Definition: strings.cpp:94
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
NetworkServerGameInfo::use_password
bool use_password
Is this server passworded?
Definition: game_info.h:102
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:477
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
NWidgetServerListHeader::visible
bool visible[6]
The visible headers.
Definition: network_gui.cpp:89
WID_NSS_COMPANIES_LABEL
@ WID_NSS_COMPANIES_LABEL
Label for 'max companies'.
Definition: network_widget.h:65
NetworkGameWindow::UpdateListPos
void UpdateListPos()
Set this->list_pos to match this->server.
Definition: network_gui.cpp:367
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_NG_NAME
@ WID_NG_NAME
'Name' button.
Definition: network_widget.h:23
_network_coordinator_client
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
Definition: network_coordinator.cpp:30
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:116
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:179
NGLS_BANNED
@ NGLS_BANNED
You are banned from this server.
Definition: network_gamelist.h:22
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
NetworkSettings::server_password
std::string server_password
password for joining this server
Definition: settings_type.h:282
NetworkPasswordType
NetworkPasswordType
The type of password we're asking for.
Definition: network_type.h:80
EventState
EventState
State of handling an event.
Definition: window_type.h:717
NGLS_ONLINE
@ NGLS_ONLINE
Server is online.
Definition: network_gamelist.h:20
WID_NG_JOIN
@ WID_NG_JOIN
'Join game' button.
Definition: network_widget.h:39
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:671
WC_NETWORK_ASK_RELAY
@ WC_NETWORK_ASK_RELAY
Network ask relay window; Window numbers:
Definition: window_type.h:483
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
WID_NSS_SETPWD
@ WID_NSS_SETPWD
'Set password' button.
Definition: network_widget.h:58
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition: fileio_type.h:20
WID_NSS_CLIENTS_BTND
@ WID_NSS_CLIENTS_BTND
'Max clients' downarrow.
Definition: network_widget.h:62
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
ButtonCommon::disabled
bool disabled
Is the button disabled?
Definition: network_gui.cpp:1424
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:43
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
WID_NG_START
@ WID_NG_START
'Start server' button.
Definition: network_widget.h:49
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
NWidgetServerListHeader::Draw
void Draw(const Window *w) override
Definition: network_gui.cpp:181
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:32
SetAlignment
static NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1060
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
CMD_COMPANY_CTRL
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
Definition: command_type.h:281
ButtonCommon::height
uint height
Calculated height of the button.
Definition: network_gui.cpp:1425
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:400
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:313
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
NetworkClientListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_gui.cpp:1753
NC_NONE
@ NC_NONE
All flags cleared.
Definition: widget_type.h:462
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
AdminClientBanCallback
static void AdminClientBanCallback(Window *w, bool confirmed)
Callback function for admin command to ban client.
Definition: network_gui.cpp:1384
ShowNetworkChatQueryWindow
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
Definition: network_chat_gui.cpp:534
ButtonCommon
Button shown for either a company or client in the client-list.
Definition: network_gui.cpp:1419
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:209
NetworkGameList
Structure with information shown in the game list (GUI)
Definition: network_gamelist.h:27
NetworkClientListWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: network_gui.cpp:1928
network.h
NetworkClientConnectGame
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password, const std::string &join_company_password)
Join a client to the server at with the given connection string.
Definition: network.cpp:762
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:356
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:338
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:457
WID_NG_CLIENT_LABEL
@ WID_NG_CLIENT_LABEL
Label in front of client name edit box.
Definition: network_widget.h:17
NGLS_OFFLINE
@ NGLS_OFFLINE
Server is offline (or cannot be queried).
Definition: network_gamelist.h:19
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
NetworkCompanyPasswordWindow::warning_size
Dimension warning_size
How much space to use for the warning text.
Definition: network_gui.cpp:2274
SPR_FLAGS_BASE
static const SpriteID SPR_FLAGS_BASE
Flags sprites (in same order as enum NetworkLanguage)
Definition: sprites.h:297
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2172
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1751
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:595
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
NetworkClientListWindow::OnMouseLoop
virtual void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: network_gui.cpp:2109
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1169
NetworkGameWindow::lock_offset
int lock_offset
Left offset for lock icon.
Definition: network_gui.cpp:235
WID_NSS_COMPANIES_TXT
@ WID_NSS_COMPANIES_TXT
'Max companies' text.
Definition: network_widget.h:67
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
WID_CL_COMPANY_JOIN
@ WID_CL_COMPANY_JOIN
Used for QueryWindow when a company has a password.
Definition: network_widget.h:91
NetworkClientListWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar of this window.
Definition: network_gui.cpp:1487
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
NetworkClientListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:1785
NetworkClientListWindow::RebuildList
void RebuildList()
Rebuild the list, meaning: calculate the lines needed and what buttons go on which line.
Definition: network_gui.cpp:1637
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:718
NetworkUpdateServerGameType
void NetworkUpdateServerGameType()
The setting server_game_type was updated; possibly we need to take some action.
Definition: network.cpp:972
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1076
ButtonCommon::sprite
SpriteID sprite
The sprite to use on the button.
Definition: network_gui.cpp:1421
NetworkServerKickClient
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
Definition: network_server.cpp:1958
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:67
WID_CL_SERVER_CONNECTION_TYPE
@ WID_CL_SERVER_CONNECTION_TYPE
The type of connection the Game Coordinator detected for this server.
Definition: network_widget.h:86
NetworkGameList::next
NetworkGameList * next
Next pointer to make a linked game list.
Definition: network_gamelist.h:36
network_gamelist.h
NetworkServerGameInfo::start_date
Date start_date
When the game started.
Definition: game_info.h:95
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition: network_type.h:92
NetworkServerGameInfo::landscape
byte landscape
The used landscape.
Definition: game_info.h:108
GREY_SCALE
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
Definition: gfx_func.h:190
NetworkClientListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_gui.cpp:1716
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:111
WID_CL_CLIENT_NAME
@ WID_CL_CLIENT_NAME
Client name.
Definition: network_widget.h:87
QueryCallbackProc
void QueryCallbackProc(Window *, bool)
Callback procedure for the ShowQuery method.
Definition: textbuf_gui.h:29
WID_NCP_OK
@ WID_NCP_OK
Safe the password etc.
Definition: network_widget.h:109
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:477
WID_NSS_LOAD_GAME
@ WID_NSS_LOAD_GAME
Load game button.
Definition: network_widget.h:71
ButtonCommon::OnClick
virtual void OnClick(struct NetworkClientListWindow *w, Point pt)=0
OnClick handler for when the button is pressed.
NetworkServerGameInfo::server_name
std::string server_name
Server name.
Definition: game_info.h:99
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:26
NetworkGameList::refreshing
bool refreshing
Whether this server is being queried.
Definition: network_gamelist.h:34
MAX_MAP_SIZE
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:66
NetworkAskRelayWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_gui.cpp:2422
ClientNetworkGameSocketHandler::SendGamePassword
static NetworkRecvStatus SendGamePassword(const std::string &password)
Set the game password as requested.
Definition: network_client.cpp:359
_network_host_list
StringList _network_host_list
The servers we know.
Definition: network.cpp:67
NetworkGameWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: network_gui.cpp:598
NetworkGameList::info
NetworkGameInfo info
The game information of this server.
Definition: network_gamelist.h:30
NetworkServerGameInfo::clients_on
byte clients_on
Current count of clients on server.
Definition: game_info.h:103
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
WN_NETWORK_STATUS_WINDOW_JOIN
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
Definition: window_type.h:31
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
Window::IsWidgetDisabled
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:415
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
NGLS_FULL
@ NGLS_FULL
Server is full and cannot be queried.
Definition: network_gamelist.h:21
NetworkServerSetCompanyPassword
void NetworkServerSetCompanyPassword(CompanyID company_id, const std::string &password, bool already_hashed)
Set/Reset a company password on the server end.
Definition: network_server.cpp:1648
NetworkGameWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_gui.cpp:716
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Company
Definition: company_base.h:115
WID_NG_DETAILS
@ WID_NG_DETAILS
Panel with game details.
Definition: network_widget.h:37
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:178
NetworkClientListWindow::CLIENT_OFFSET_LEFT
static const int CLIENT_OFFSET_LEFT
Offset of client entries compared to company entries.
Definition: network_gui.cpp:1496
_network_server_invite_code
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
Definition: network_coordinator.cpp:32
WID_NG_FILTER_LABEL
@ WID_NG_FILTER_LABEL
Label in front of the filter/search edit box.
Definition: network_widget.h:19
NetworkGameListRemoveItem
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
Definition: network_gamelist.cpp:64
NetworkJoinStatusWindow
Definition: network_gui.cpp:2138
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
NetworkServerGameInfo::grfconfig
GRFConfig * grfconfig
List of NewGRF files used.
Definition: game_info.h:94
SetDParamMaxDigits
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:110
NetworkJoinStatusWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: network_gui.cpp:2216
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:866
_network_join_bytes
uint32 _network_join_bytes
The number of bytes we already downloaded.
Definition: network_gui.cpp:2135
NetworkGameWindow::list_pos
ServerListPosition list_pos
Position of the selected server.
Definition: network_gui.cpp:228
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
WID_NG_LASTJOINED_SPACER
@ WID_NG_LASTJOINED_SPACER
Spacer after last joined server panel.
Definition: network_widget.h:35
NetworkGameWindow::NGameMapSizeSorter
static bool NGameMapSizeSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by map size.
Definition: network_gui.cpp:317
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:40
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1000
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
_is_network_server
bool _is_network_server
Does this client wants to be a network-server?
Definition: network.cpp:61
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
NetworkAskRelayWindow::FindWindowPlacementAndResize
void FindWindowPlacementAndResize(int def_width, int def_height) override
Resize window towards the default size.
Definition: network_gui.cpp:2414
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
NetworkClientListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_gui.cpp:2074
NetworkGameInfo::compatible
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
Definition: game_info.h:119
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
NetworkGameWindow::flag_offset
int flag_offset
Left offset for language flag icon.
Definition: network_gui.cpp:237
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:296
NetworkServerGameInfo::map_height
uint16 map_height
Map height.
Definition: game_info.h:98
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WID_NAR_CAPTION
@ WID_NAR_CAPTION
Caption of the window.
Definition: network_widget.h:114
NETWORK_GAME_PASSWORD
@ NETWORK_GAME_PASSWORD
The password of the game.
Definition: network_type.h:81
NetworkGameWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: network_gui.cpp:869
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1028
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
ShowNetworkAskRelay
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
Show a modal confirmation window with "no" / "yes, once" / "yes, always" buttons.
Definition: network_gui.cpp:2482
NetworkSettings::max_companies
uint8 max_companies
maximum amount of companies
Definition: settings_type.h:293
NetworkCompanyPasswordWindow::UpdateWidgetSize
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.
Definition: network_gui.cpp:2298
NetworkGameList::status
NetworkGameListStatus status
Stats of the server.
Definition: network_gamelist.h:32
DrawCompanyIcon
void DrawCompanyIcon(CompanyID cid, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:143
ButtonCommon::width
uint width
Calculated width of the button.
Definition: network_gui.cpp:1426
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092
WID_NG_DETAILS_SPACER
@ WID_NG_DETAILS_SPACER
Spacer for game actual details.
Definition: network_widget.h:38