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

OpenTTD Source 14.0-beta3

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