48#include "table/strings.h"
52# include <emscripten.h>
98 leaf->SetResize(1, 0);
100 this->
Add(std::move(leaf));
109 this->
Add(std::move(leaf));
121 for (
const auto &child_wid : this->
children) {
122 child_wid->SetupSmallestSize(w);
123 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
127 for (
const auto &child_wid : this->children) {
128 child_wid->current_x = child_wid->smallest_x;
132 this->
smallest_x = this->children.front()->smallest_x + this->children.back()->smallest_x;
133 this->ApplyAspectRatio();
145 given_width -= this->
children.back()->smallest_x;
148 auto first = std::next(std::begin(this->
children));
149 auto last = std::prev(std::end(this->
children));
150 for (
auto it = first; it != last; ++it) {
151 auto &child_wid = *it;
153 given_width -= child_wid->smallest_x;
154 child_wid->current_x = child_wid->smallest_x;
156 child_wid->current_x = 0;
162 this->
children.front()->current_x = given_width;
166 auto assign_position = [&](
const std::unique_ptr<NWidgetBase> &child_wid) {
167 if (child_wid->current_x != 0) {
168 child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
169 position += child_wid->current_x;
174 std::for_each(std::rbegin(this->
children), std::rend(this->
children), assign_position);
176 std::for_each(std::begin(this->
children), std::end(this->
children), assign_position);
188 static const std::initializer_list<GUIGameServerList::SortFunction * const>
sorter_funcs;
190 static const std::initializer_list<GUIGameServerList::FilterFunction * const>
filter_funcs;
214 this->servers.clear();
216 bool found_current_server =
false;
217 bool found_last_joined =
false;
219 this->servers.push_back(ngl.get());
220 if (ngl.get() == this->server) {
221 found_current_server =
true;
223 if (ngl.get() == this->last_joined) {
224 found_last_joined =
true;
228 if (!found_last_joined) {
229 this->last_joined =
nullptr;
231 if (!found_current_server) {
232 this->server =
nullptr;
248 this->vscroll->
SetCount(this->servers.size());
251 this->servers.
Sort();
337 auto it = std::ranges::find(this->servers, this->server);
338 if (it == std::end(this->servers)) {
341 this->list_pos =
static_cast<ServerListPosition>(std::distance(std::begin(this->servers), it));
348 assert(item !=
nullptr);
349 assert((*item) !=
nullptr);
352 filter.AddLine((*item)->info.server_name);
369 Rect r = {std::min(name.left, info.left), y, std::max(name.right, info.right), y + (int)this->
resize.step_height - 1};
383 Rect clients = nwid->GetCurrentRect();
384 DrawString(clients.left, clients.right, y + text_y_offset,
391 Rect mapsize = nwid->GetCurrentRect();
392 DrawString(mapsize.left, mapsize.right, y + text_y_offset,
399 Rect date = nwid->GetCurrentRect();
401 DrawString(date.left, date.right, y + text_y_offset,
408 Rect years = nwid->GetCurrentRect();
410 DrawString(years.left, years.right, y + text_y_offset,
411 GetString(STR_NETWORK_SERVER_LIST_PLAY_TIME_SHORT, play_time / 60 / 60, (play_time / 60) % 60),
417 info.bottom = y + this->
resize.step_height - 1;
426 DrawSpriteIgnorePadding(SPR_BLOT, pal, info.
WithWidth(this->blot.width, !rtl),
SA_CENTER);
466 EM_ASM(
if (window[
"openttd_server_list"]) openttd_server_list());
470 this->server = this->last_joined;
481 this->last_sorting = this->servers.
GetListing();
495 size.height = 12 *
resize.height;
503 size.width = NWidgetScrollbar::GetVerticalDimension().width;
533 size.height = std::max(this->lock.height, this->blot.height) + padding.height;
545 for (
auto it = first; it != last; ++it) {
548 y += this->
resize.step_height;
555 if (this->last_joined !=
nullptr) this->
DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
595 bool changed =
false;
619 if (this->server ==
nullptr)
return STR_NETWORK_SERVER_LIST_GAME_INFO;
620 switch (this->server->
status) {
621 case NGLS_OFFLINE:
return STR_NETWORK_SERVER_LIST_SERVER_OFFLINE;
622 case NGLS_ONLINE:
return STR_NETWORK_SERVER_LIST_GAME_INFO;
623 case NGLS_FULL:
return STR_NETWORK_SERVER_LIST_SERVER_FULL;
624 case NGLS_BANNED:
return STR_NETWORK_SERVER_LIST_SERVER_BANNED;
625 case NGLS_TOO_OLD:
return STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD;
626 default: NOT_REACHED();
646 tr.top += header_height;
652 if (sel ==
nullptr)
return;
666 StringID invite_or_address = sel->
connection_string.starts_with(
"+") ? STR_NETWORK_SERVER_LIST_INVITE_CODE : STR_NETWORK_SERVER_LIST_SERVER_ADDRESS;
716 this->server = (it != this->servers.end()) ? *it :
nullptr;
725 if (this->last_joined !=
nullptr) {
726 this->server = this->last_joined;
740 this->searched_internet =
true;
750 STR_NETWORK_SERVER_LIST_ENTER_SERVER_ADDRESS,
760 if (this->server !=
nullptr) {
784 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
798 this->server = this->servers[this->list_pos];
808 if (this->server !=
nullptr) {
809 if (keycode == WKC_DELETE) {
811 if (this->server == this->last_joined) this->last_joined =
nullptr;
812 this->server =
nullptr;
841 if (!str.has_value() || str->empty())
return;
855 if (!this->searched_internet)
return;
891 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
895 NWidgetFunction([]() -> std::unique_ptr<NWidgetBase> {
return std::make_unique<NWidgetServerListHeader>(); }),
906 SetToolTip(STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST_TOOLTIP),
917 SetStringTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
964 static bool first =
true;
1020 size.width += padding.width;
1021 size.height += padding.height;
1058 default: NOT_REACHED();
1129 std::string str{this->name_editbox.text.
GetText()};
1143 if (!str.has_value())
return;
1149 if (!value.has_value())
return;
1151 switch (this->widget_id) {
1152 default: NOT_REACHED();
1296 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_CL_MATRIX),
SetMinimalSize(180, 0),
SetResize(1, 1),
SetFill(1, 1),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_CL_SCROLLBAR),
1301 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_CL_CLIENT_COMPANY_COUNT),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(
WidgetDimensions::unscaled.framerect),
SetAlignment(
SA_CENTER),
SetToolTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP),
1309 WDP_AUTO,
"list_clients", 220, 300,
1392template <
typename T>
1414 assert(
proc !=
nullptr);
1421 this->
proc(w, pt, this->
id);
1433 std::vector<std::unique_ptr<ButtonCommon>>
buttons{};
1449 template <
typename T,
typename...TArgs>
1452 auto &button = this->buttons.emplace_back(std::make_unique<T>(std::forward<TArgs &&>(args)...));
1453 return static_cast<T &
>(*button);
1465 for (
auto &button : this->buttons) {
1481 if (button ==
nullptr)
return {};
1494 for (
auto &button :
buttons) {
1497 DrawSpriteIgnorePadding(button->sprite, PAL_NONE, br,
SA_CENTER);
1498 if (button->disabled) {
1523 DrawSpriteIgnorePadding(SPR_COMPANY_ICON, pal, r.
WithWidth(d.width, rtl),
SA_CENTER);
1527 DrawString(tr, STR_NETWORK_CLIENT_LIST_SPECTATORS, TC_SILVER);
1529 DrawString(tr, STR_NETWORK_CLIENT_LIST_NEW_COMPANY, TC_WHITE);
1551 if (ci ==
nullptr)
return;
1560 player_icon = SPR_PLAYER_SELF;
1562 player_icon = SPR_PLAYER_HOST;
1565 if (player_icon != 0) {
1567 DrawSpriteIgnorePadding(player_icon, PALETTE_TO_GREY, r.
WithWidth(d.width, rtl),
SA_CENTER);
1581 if (ci !=
nullptr) {
1623 std::vector<std::unique_ptr<ButtonLine>>
buttons{};
1669 wi_rect.left = pt.
x;
1670 wi_rect.right = pt.
x;
1672 wi_rect.bottom = pt.
y;
1694 wi_rect.left = pt.
x;
1695 wi_rect.right = pt.
x;
1697 wi_rect.bottom = pt.
y;
1730 ButtonLine &company_line = *this->buttons.emplace_back(std::make_unique<CompanyButtonLine>(company_id));
1737 bool has_players =
false;
1739 if (ci->client_playas != company_id)
continue;
1742 ButtonLine &line = *this->buttons.emplace_back(std::make_unique<ClientButtonLine>(ci->index));
1749 chat_button.
disabled = !has_players;
1760 this->buttons.clear();
1774 if (c->index == client_playas)
continue;
1782 this->vscroll->
SetCount(this->buttons.size());
1804 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1826 size.width = std::min(size.width,
static_cast<uint
>(
ScaleGUITrad(200)));
1832 size.width += padding.width;
1833 size.height += padding.height;
1842 fill.height =
resize.height = this->line_height;
1843 size.height = std::max(size.height, 5 * this->line_height);
1906 if (it == std::end(this->buttons))
break;
1910 if (button ==
nullptr)
break;
1923 if (it == std::end(this->buttons))
break;
1926 auto tooltip = (*it)->GetTooltip(r, pt);
1927 if (!tooltip.has_value())
break;
1994 assert(callback !=
nullptr);
2014 if (!str.has_value())
return;
2016 switch (this->query_widget) {
2017 default: NOT_REACHED();
2041 if (this->hover_index >= 0) {
2047 for (
auto it = first; it != last; ++it) {
2049 ir = ir.
Translate(0, this->line_height);
2060 if (this->hover_index != -1) {
2061 this->hover_index = -1;
2066 if (index != this->hover_index) {
2067 this->hover_index = index;
2087 std::shared_ptr<NetworkAuthenticationPasswordRequest>
request{};
2188 if (!str.has_value() || str->empty() || this->request ==
nullptr) {
2193 this->request->Reply(*str);
2231 if (w ==
nullptr)
return;
2232 w->
request = std::move(request);
2286 this->
left =
Clamp(
parent->left + (
parent->width / 2) - (this->width / 2), 0, _screen.width - this->width);
2287 this->
top =
Clamp(
parent->top + (
parent->height / 2) - (this->height / 2), 0, _screen.height - this->height);
2345void ShowNetworkAskRelay(std::string_view server_connection_string, std::string &&relay_connection_string, std::string &&token)
2386 this->
left =
Clamp(
parent->left + (
parent->width / 2) - (this->width / 2), 0, _screen.width - this->width);
2387 this->
top =
Clamp(
parent->top + (
parent->height / 2) - (this->height / 2), 0, _screen.height - this->height);
2469 this->ConstructWindow();
Container for an encoded string, created by GetEncodedString.
List template of 'things' T to sort in a GUI.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetListing(Listing l)
Import sort conditions.
void SetFilterState(bool state)
Enable or disable the filter.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Window with the list of game servers.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnPaint() override
The window must be repainted.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawDetails(const Rect &r) const
Draw the details about the selected server.
QueryString filter_editbox
Editbox for filter on servers.
Scrollbar * vscroll
Vertical scrollbar of the list of servers.
StringID GetHeaderString() const
Get the string for the header of the 'selected server' subpanel.
void BuildGUINetworkGameList()
(Re)build the GUI network game list (a.k.a.
static bool NGameNameSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by name.
static bool NGameTicksPlayingSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by the number of ticks the game is running.
void UpdateListPos()
Set this->list_pos to match this->server.
void OnInit() override
Notification that the nested widget tree gets initialized.
const IntervalTimer< TimerWindow > refresh_interval
Refresh the online servers on a regular interval.
static bool NGameAllowedSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by joinability.
NetworkGame * server
Selected server.
NetworkGame * last_joined
The last joined server.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void DrawServerLine(const NetworkGame *cur_item, int y, bool highlight) const
Draw a single server line.
void OnResize() override
Called after the window got resized.
static bool NGameCalendarDateSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by calendar date.
void ScrollToSelectedServer()
Scroll the list up or down to the currently selected server.
~NetworkGameWindow() override
Save the last sorting state.
static const std::initializer_list< GUIGameServerList::SortFunction *const > sorter_funcs
Functions for sorting servers.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
ServerListPosition list_pos
Position of the selected server.
static bool NGameClientSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by the amount of clients online on a server.
void SortNetworkGameList()
Sort the server list.
Dimension blot
Dimension of compatibility icon.
static bool NGameSearchFilter(NetworkGame *const *item, StringFilter &filter)
Filter the servers by the server name.
static Listing last_sorting
Runtime saved values.
static bool NGameMapSizeSorter(NetworkGame *const &a, NetworkGame *const &b)
Sort servers by map size.
static const std::initializer_list< GUIGameServerList::FilterFunction *const > filter_funcs
Functions for filtering servers.
GUIGameServerList servers
List with game servers.
bool searched_internet
Did we ever press "Search Internet" button?
Dimension lock
Dimension of lock icon.
QueryString name_editbox
Client name editbox.
NetworkGameWindow(WindowDesc &desc)
Create the window.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static constexpr bool IsSurveyPossible()
Check whether a survey is possible.
@ Preview
User is previewing the survey result.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Functions related to commands.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Command definitions related to companies.
Functions related to companies.
@ New
Create a new company.
@ Delete
Delete a company.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
@ AddKey
Create a public key.
@ AllowListed
Allow only listed keys to join the company.
@ AllowAny
Allow joining the company without a key.
static constexpr CompanyID COMPANY_NEW_COMPANY
The client wants a new company.
@ None
Dummy reason for actions that don't need one.
@ Manual
The company is manually removed.
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
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...
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
static const std::string NETWORK_SURVEY_DETAILS_LINK
Link with more details & privacy statement of the survey.
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0'.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ InstantClose
Set if releasing mouse button should close the list regardless of where the cursor is.
#define T
Climate temperate.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
@ Load
File is being loaded.
@ Savegame
old or new savegame
@ Scenario
old or new scenario
@ Heightmap
heightmap file
Declarations for savegames operations.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Functions related to world/map generation.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
void ShowGenerateLandscape()
Start with a normal game.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
bool _left_button_clicked
Is left mouse button clicked?
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.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Functions related to the gfx engine.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ Normal
Index of the normal font in the font tables.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_CENTER
Center both horizontally and vertically.
@ SA_VERT_CENTER
Vertically center the text.
uint32_t PaletteID
The number of the palette.
Colours
One of 16 base colours used for companies and windows/widgets.
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
GUI functions that shouldn't be here.
#define Point
Macro that prevents name conflicts between included headers.
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
void ShowQuery(EncodedString &&caption, EncodedString &&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...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _is_network_server
Does this client wants to be a network-server?
StringList _network_host_list
The servers we know.
void NetworkQueryServer(std::string_view connection_string)
Query a server to fetch the game-info.
void NetworkDisconnect(bool close_admins)
We want to disconnect from the host/clients.
bool _network_server
network-server is active
NetworkGame * NetworkAddServer(std::string_view connection_string, bool manually, bool never_expire)
Validates an address entered as a string and adds the server to the list.
bool NetworkClientConnectGame(std::string_view connection_string, CompanyID default_company, const std::string &join_server_password)
Join a client to the server at with the given connection string.
void NetworkRebuildHostList()
Generates the list of manually added hosts from NetworkGame and dumps them into the array _network_ho...
ClientID _network_own_client_id
Our client identifier.
void NetworkUpdateServerGameType()
The setting server_game_type was updated; possibly we need to take some action.
bool NetworkValidateServerName(std::string &server_name)
Trim the given server name in place, i.e.
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void ShowNetworkChatQueryWindow(NetworkChatDestinationType type, int dest)
Show the chat window.
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
uint NetworkMaxCompaniesAllowed()
Get the maximum number of companies that are allowed by the server.
std::string _network_server_name
The current name of the server you are on.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
Client part of the network protocol.
Part of the network protocol handling content distribution.
void ShowMissingContentWindow(const GRFConfigList &list)
Show the content list window with all missing grfs from the given list.
ConnectionType _network_server_connection_type
What type of connection the Game Coordinator detected we are on.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
std::string _network_server_invite_code
Our invite code as indicated by the Game Coordinator.
Part of the network protocol handling Game Coordinator requests.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
void NetworkServerKickClient(ClientID client_id, std::string_view reason)
Kick a single client.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason)
Ban, or kick, everyone joined from the given client's IP.
void NetworkGameListRemoveItem(NetworkGame *remove)
Remove an item from the gamelist linked list.
std::vector< std::unique_ptr< NetworkGame > > _network_game_list
Game list of this client.
Handling of the list of games.
@ NGLS_ONLINE
Server is online.
@ NGLS_FULL
Server is full and cannot be queried.
@ NGLS_TOO_OLD
Server is too old to query.
@ NGLS_OFFLINE
Server is offline (or cannot be queried).
@ NGLS_BANNED
You are banned from this server.
int ServerListPosition
A location within the server list.
static void AdminCompanyResetCallback(Window *, bool confirmed)
Callback function for admin command to reset company.
static WindowDesc _network_start_server_window_desc(WDP_CENTER, {}, 0, 0, WC_NETWORK_WINDOW, WC_NONE, {}, _nested_network_start_server_window_widgets)
Description of the NetworkStartServerWindow.
void ShowNetworkGameWindow()
Show the server list window.
static constexpr std::initializer_list< NWidgetPart > _nested_network_start_server_window_widgets
Widgets and the structure of the NetworkStartServerWindow.
static WindowDesc _client_list_desc(WDP_AUTO, "list_clients", 220, 300, WC_CLIENT_LIST, WC_NONE, {}, _nested_client_list_widgets)
Description of the NetworkClientListWindow.
NetworkJoinStatus _network_join_status
The status of joining.
static void AdminClientKickCallback(Window *, bool confirmed)
Callback function for admin command to kick client.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
uint8_t _network_join_waiting
The number of clients waiting in front of us.
void ShowJoinStatusWindow()
Open the window showing the status of joining the server.
static constexpr std::initializer_list< NWidgetPart > _nested_network_join_status_window_widgets
Widgets and the structure of the NetworkJoinStatusWindow.
static WindowDesc _network_game_window_desc(WDP_CENTER, "list_servers", 1000, 730, WC_NETWORK_WINDOW, WC_NONE, {}, _nested_network_game_widgets)
Description of the NetworkGameWindow.
Button< CompanyID > CompanyButton
Button linked to a company.
static WindowDesc _network_join_status_window_desc(WDP_CENTER, {}, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WindowDefaultFlag::Modal, _nested_network_join_status_window_widgets)
Description of the NetworkJoinStatusWindow.
static const ServerListPosition SLP_INVALID
Sentinel for an invalid location in the server list.
void ShowSurveyResultTextfileWindow(Window *parent)
Show the surver results as a text file.
static constexpr std::initializer_list< NWidgetPart > _nested_network_ask_relay_widgets
Widgets and the structure of the NetworkAskRelayWindow.
static void AdminClientBanCallback(Window *, bool confirmed)
Callback function for admin command to ban client.
void DrawCompanyIcon(CompanyID cid, int x, int y)
Draw the icon of a company.
static constexpr std::initializer_list< NWidgetPart > _nested_client_list_widgets
Widgets and the structure of the NetworkClientListWindow.
static DropDownList BuildVisibilityDropDownList()
Create the dropdown with visibility options for the server.
static WindowDesc _network_ask_relay_desc(WDP_CENTER, {}, 0, 0, WC_NETWORK_ASK_RELAY, WC_NONE, WindowDefaultFlag::Modal, _nested_network_ask_relay_widgets)
Description of the NetworkAskRelayWindow.
GUIList< NetworkGame *, std::nullptr_t, StringFilter & > GUIGameServerList
The list of servers with sorting/filtering.
static constexpr std::initializer_list< NWidgetPart > _nested_network_ask_survey_widgets
Widgets and the structure of the NetworkAskSurveyWindow.
static WindowDesc _network_ask_survey_desc(WDP_CENTER, {}, 0, 0, WC_NETWORK_ASK_SURVEY, WC_NONE, WindowDefaultFlag::Modal, _nested_network_ask_survey_widgets)
Description of the NetworkAskSurveyWindow.
void ShowClientList()
Open the client list window.
static constexpr std::initializer_list< NWidgetPart > _nested_network_game_widgets
Widgets and the structure of the NetworkGameWindow.
uint32_t _network_join_bytes_total
The total number of bytes to download.
void ShowNetworkAskRelay(std::string_view server_connection_string, std::string &&relay_connection_string, std::string &&token)
Show a modal confirmation window with "no" / "yes, once" / "yes, always" buttons.
uint32_t _network_join_bytes
The number of bytes we already downloaded.
Button< ClientID > ClientButton
Button linked to a client.
void ShowNetworkAskSurvey()
Show a modal confirmation window with "no" / "preview" / "yes" buttons.
void ShowNetworkNeedPassword(std::shared_ptr< NetworkAuthenticationPasswordRequest > request)
Update the NetworkJoinStatusWindow to start requesting the server password.
static CompanyID _admin_company_id
For what company a confirmation window is open.
static ClientID _admin_client_id
For what client a confirmation window is open.
static void ShowNetworkStartServerWindow()
Show the window to configure and start your server with.
GUIs related to networking.
@ NRWCD_UNHANDLED
Relay request is unhandled.
@ NRWCD_HANDLED
Relay request is handled, either by user or by timeout.
NetworkJoinStatus
Status of the clients during joining.
@ Waiting
Waiting for other clients to finish downloading the map.
@ End
Sentinel for end-of-enumeration.
@ Authorizing
Starting authorizing the client to join the game and optionally company.
@ Downloading
Downloading the map from the server.
@ Connecting
Opening the connection to the server.
Server part of the network protocol.
NetworkSurveyHandler _survey
The handler for sending surveys for statistics.
Part of the network protocol handling opt-in survey.
static const uint MAX_CLIENTS
How many clients can we have.
@ Client
Send message/notice to only a certain client (Private).
@ Team
Send message/notice to everyone playing the same company (Team).
ClientID
'Unique' identifier to be given to clients
@ INVALID_CLIENT_ID
Client is not part of anything.
@ CLIENT_ID_SERVER
Servers always have this ID.
ServerGameType
Game type the server can be using.
@ Public
The game is publicly accessible.
@ Local
Do not communicate with the game coordinator.
@ InviteOnly
The game can be accessed if you know the invite code.
PoolID< uint16_t, struct ClientPoolIDTag, MAX_CLIENTS+1, 0xFFFF > ClientPoolID
Indices into the client related pools.
void NetworkUDPSearchGame()
Find all servers.
Sending and receiving UDP messages.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
@ SM_MENU
Switch to game intro menu.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
constexpr PixelColour GREY_SCALE(uint8_t level)
Return the colour for a particular greyscale level.
static constexpr PixelColour PC_GREY
Grey palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
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.
static const SettingDesc * GetSettingFromName(std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
ClientSettings _settings_client
The current settings for this game.
Functions and types used internally for the settings configurations.
Base types for having sorted lists in GUIs.
Base for drawing complex sprites.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Searching and filtering using a stringterm.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Dimensions (a width and height) of a rectangle in 2D.
Information about GRF, used in the game and (part of it) in savegames.
Data structure describing how to show the list (what sort direction and criteria).
Window used for asking the user if he is okay using a relay server.
void FindWindowPlacementAndResize(int, int, bool) override
Resize window towards the default size.
std::string relay_connection_string
The relay server we want to connect to.
NetworkAskRelayWindow(WindowDesc &desc, Window *parent, std::string_view server_connection_string, std::string &&relay_connection_string, std::string &&token)
Create the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::string token
The token for this connection.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string server_connection_string
The game server we want to connect to.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Window used for asking if the user wants to participate in the automated survey.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void FindWindowPlacementAndResize(int, int, bool) override
Resize window towards the default size.
NetworkAskSurveyWindow(WindowDesc &desc, Window *parent)
Create the window.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
CompanyID client_playas
As which company is this client playing (CompanyID).
ClientID client_id
Client identifier (same as ClientState->client_id).
std::string client_name
Name of the client.
std::string public_key
The public key of the client.
Main handle for clientlist.
Scrollbar * vscroll
Vertical scrollbar of this window.
void OnResize() override
Called after the window got resized.
static void OnClickCompanyNew(NetworkClientListWindow *, Point, CompanyID)
Create new company button is clicked.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
ClientListWidgets query_widget
During a query this tracks what widget caused the query.
CompanyID dd_company_id
During admin dropdown, track which company this was for.
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
int hover_index
Index of the current line we are hovering over, or -1 if none.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
std::vector< std::unique_ptr< ButtonLine > > buttons
Per line which buttons are available.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
uint line_height
Current lineheight of each entry in the matrix.
void OnInit() override
Notification that the nested widget tree gets initialized.
static void OnClickCompanyAdmin(NetworkClientListWindow *w, Point pt, CompanyID company_id)
Admin button on a Company is clicked.
static void OnClickClientChat(NetworkClientListWindow *, Point, ClientID client_id)
Chat button on a Client is clicked.
ClientID dd_client_id
During admin dropdown, track which client this was for.
void RebuildListCompany(CompanyID company_id, CompanyID client_playas, bool can_join_company)
Part of RebuildList() to create the information for a single company.
static void OnClickClientAuthorize(NetworkClientListWindow *, Point, ClientID client_id)
Authorize button on a Client is clicked.
static void OnClickClientAdmin(NetworkClientListWindow *w, Point pt, ClientID client_id)
Admin button on a Client is clicked.
static void OnClickCompanyChat(NetworkClientListWindow *, Point, CompanyID company_id)
Chat button on a Company is clicked.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
DropDownAction
The possible entries in a DropDown for an admin action.
@ CompanyAllowListed
Allow only listed clients.
@ CompanyAllowAny
Allow any client.
@ AdminKickClient
Admin kick client.
@ AdminResetCompany
Admin reset company.
@ AdminBanClient
Admin ban client.
static void OnClickCompanyJoin(NetworkClientListWindow *, Point, CompanyID company_id)
Join button on a Company is clicked.
void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close) override
A dropdown window associated to this window has been closed.
NetworkClientListWindow(WindowDesc &desc, WindowNumber window_number)
Create the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void RebuildList()
Rebuild the list, meaning: calculate the lines needed and what buttons go on which line.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
bool version_compatible
Can we connect to this server or not? (based on server_revision).
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
Structure with information shown in the game list (GUI).
bool refreshing
Whether this server is being queried.
std::string connection_string
Address of the server.
NetworkGameInfo info
The game information of this server.
NetworkGameStatus status
Stats of the server.
Window showing the progress during joining.
NetworkJoinStatusWindow(WindowDesc &desc)
Create the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::shared_ptr< NetworkAuthenticationPasswordRequest > request
Callback to send the password request result to.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
TimerGameCalendar::Date calendar_start
When the game started.
std::string server_revision
The version number the server is using (e.g.: 'r304' or 0.5.0).
bool use_password
Is this server passworded?
uint8_t clients_max
Max clients allowed on server.
GRFConfigList grfconfig
List of NewGRF files used.
uint16_t map_height
Map height.
std::string server_name
Server name.
uint16_t map_width
Map width.
TimerGameTick::TickCounter ticks_playing
Amount of ticks the game has been running unpaused.
LandscapeType landscape
The used landscape.
uint8_t companies_max
Max companies allowed on server.
std::string gamescript_name
Name of the gamescript.
TimerGameCalendar::Date calendar_date
Current calendar date.
int gamescript_version
Version of the gamescript.
uint8_t companies_on
How many started companies do we have.
uint8_t clients_on
Current count of clients on server.
Window to configure and start your server with.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
NetworkStartServerWindow(WindowDesc &desc)
Create the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
WidgetID widget_id
The widget that has the pop-up input menu.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
bool CheckServerName()
Check whether the currently entered server name is valid, and if so update the server_name setting.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
QueryString name_editbox
Server name editbox.
void OnTimeout() override
Called when this window's timeout has been reached.
static Pool::IterateWrapper< NetworkClientInfo > Iterate(size_t from=0)
static Company * Get(auto index)
static size_t GetNumItems()
static bool IsValidID(auto index)
static NetworkClientInfo * GetIfValid(auto index)
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
Window for displaying the textfile of a survey result.
const GRFConfig * grf_config
View the textfile of this GRFConfig.
SurveyResultTextfileWindow(Window *parent, TextfileType file_type)
Create the window.
std::string_view GetText() const
Get the current text.
void Assign(std::string_view text)
Copy a string into the textbuffer.
void LoadText(std::string_view buf)
Load a text into the textfile viewer.
TextfileType file_type
Type of textfile to view.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
A dropdown window associated to this window has been closed.
int left
x position of left edge of the window
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
int top
y position of top edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction).
WindowNumber window_number
Window number within the window class.
@ CONNECTION_TYPE_UNKNOWN
The Game Coordinator hasn't informed us yet what type of connection we have.
@ AcceptUnchanged
return success even when the text didn't change
@ LengthIsInChars
the length of the string is counted in characters
void QueryCallbackProc(Window *, bool)
Callback procedure for the ShowQuery method.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_SURVEY_RESULT
Survey result (preview).
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the Window system.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * GetMainWindow()
Get the main window, i.e.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
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-...
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
@ BorderOnly
Draw border only, no background.
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Timeout
Window timeout counter.
@ SBS_DOWN
Sort ascending.
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
@ WN_NETWORK_WINDOW_GAME
Network game window.
@ WN_NETWORK_WINDOW_START
Network start server.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NETWORK_ASK_RELAY
Network ask relay window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_CLIENT_LIST
Client list; Window numbers:
@ WC_NETWORK_WINDOW
Network window; Window numbers:
@ WC_TEXTFILE
textfile; Window numbers:
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
@ WC_NETWORK_ASK_SURVEY
Network ask survey window; Window numbers:
Functions related to zooming.