Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

# NetworkGameWindow Class Reference

Inheritance diagram for NetworkGameWindow:

## Public Member Functions
| NetworkGameWindow (const WindowDesc *desc)
virtual void | SetStringParameters (int widget) const
| Initialize string parameters for a widget.
virtual void | UpdateWidgetSize (int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
| Update size and resize step of a widget in the window.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual void | OnPaint ()
| The window must be repainted.
void | DrawDetails (const Rect &r) const
virtual void | OnClick (Point pt, int widget, int click_count)
| A click with the left mouse button has been made on the window.
virtual void | OnDropdownSelect (int widget, int index)
| A dropdown option associated to this window has been selected.
virtual void | OnInvalidateData (int data=0, bool gui_scope=true)
| Some data on this window has become invalid.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
virtual void | OnEditboxChanged (int wid)
| The text in an editbox has been edited.
virtual void | OnQueryTextFinished (char *str)
| The query window opened from this window has closed.
virtual void | OnResize ()
| Called after the window got resized.
virtual void | OnTick ()
| Called once per (game) tick.
## Protected Member Functions
void | BuildGUINetworkGameList ()
| (Re)build the GUI network game list (a.k.a.
void | SortNetworkGameList ()
| Sort the server list.
void | UpdateListPos ()
| Set this->list_pos to match this->server.
void | DrawServerLine (const NetworkGameList *cur_item, uint y, bool highlight) const
| Draw a single server line.
void | ScrollToSelectedServer ()
| Scroll the list up or down to the currently selected server.
## Static Protected Member Functions
static const char * | SkipGarbage (const char *str)
| Skip some of the 'garbage' in the string that we don't want to use to sort on.
static int CDECL | NGameNameSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by name.
static int CDECL | NGameClientSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by the amount of clients online on a server.
static int CDECL | NGameMapSizeSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by map size.
static int CDECL | NGameDateSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by current date.
static int CDECL | NGameYearsSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by the number of days the game is running.
static int CDECL | NGameAllowedSorter (NetworkGameList *const *a, NetworkGameList *const *b)
| Sort servers by joinability.
static bool CDECL | NGameSearchFilter (NetworkGameList *const *item, StringFilter &sf)
## Protected Attributes
NetworkGameList * | server
| selected server
NetworkGameList * | last_joined
| the last joined server
GUIGameServerList | servers
| list with game servers.
ServerListPosition | list_pos
| position of the selected server
Scrollbar * | vscroll
| vertical scrollbar of the list of servers
QueryString | name_editbox
| Client name editbox.
QueryString | filter_editbox
| Editbox for filter on servers.
## Static Protected Attributes
static Listing | last_sorting = {false, 5}
static GUIGameServerList::SortFunction *const | sorter_funcs []
static GUIGameServerList::FilterFunction *const | filter_funcs []

## Detailed Description

Definition at line 214 of file network_gui.cpp.

## Member Function Documentation

void NetworkGameWindow::BuildGUINetworkGameList | ( |  | ) | `[inline, protected]`

(Re)build the GUI network game list (a.k.a.

this->servers) as some major change has occurred. It ensures appropriate filtering and sorting, if both or either one is enabled.

Definition at line 236 of file network_gui.cpp.

References _network_game_list, SmallVector< T, S >::Append(), Textbuf::buf, SmallVector< T, S >::Clear(), SmallVector< T, S >::Compact(), GUIList< T, F >::Filter(), filter_editbox, StringFilter::IsEmpty(), SmallVector< T, S >::Length(), GUIList< T, F >::NeedRebuild(), NetworkGameList::next, GUIList< T, F >::RebuildDone(), servers, Scrollbar::SetCount(), GUIList< T, F >::SetFilterState(), StringFilter::SetFilterTerm(), GUIList< T, F >::Sort(), UpdateListPos(), and vscroll.

Referenced by OnEditboxChanged(), and OnPaint().

void NetworkGameWindow::DrawServerLine | ( | const NetworkGameList * | cur_item,
|  | uint | y,
|  | bool | highlight |
| ) |  |  | const`[inline, protected]`

Draw a single server line.

Parameters:

  | cur_item | the server to draw.
  | y | from where to draw?
  | highlight | does the line need to be highlighted?

Definition at line 383 of file network_gui.cpp.

References NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::companies_max, NetworkGameInfo::companies_on, NetworkGameInfo::compatible, ConvertDateToYMD(), NWidgetBase::current_x, DrawSprite(), DrawString(), FONT_HEIGHT_NORMAL, NetworkGameInfo::game_date, GfxFillRect(), NetworkGameList::info, NWidgetServerListHeader::IsWidgetVisible(), NetworkGameInfo::map_height, NetworkGameInfo::map_width, NetworkGameList::online, PC_GREY, NWidgetBase::pos_x, SA_HOR_CENTER, NetworkGameInfo::server_lang, NetworkGameInfo::server_name, SetDParam(), SPR_FLAGS_BASE, NetworkGameInfo::start_date, NetworkGameInfo::use_password, NetworkGameInfo::version_compatible, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, WID_NG_CLIENTS, WID_NG_DATE, WID_NG_MAPSIZE, and WID_NG_YEARS.

Referenced by DrawWidget().

virtual void NetworkGameWindow::DrawWidget | ( | const Rect & | r,
|  | int | widget |
| ) |  |  | const`[inline, virtual]`

Draw the contents of a nested widget.

Parameters:

  | r | Rectangle occupied by the widget.
  | widget | Number of the widget to draw.

Note:
  This method may not change any state, it may only use drawing functions.

Reimplemented from Window.

Definition at line 557 of file network_gui.cpp.

References DrawServerLine(), Window::DrawSortButtonState(), Scrollbar::GetCapacity(), Scrollbar::GetPosition(), GUIList< T, F >::IsDescSortOrder(), last_joined, SmallVector< T, S >::Length(), max(), min(), Window::resize, SBS_DOWN, server, servers, GUIList< T, F >::SortType(), ResizeInfo::step_height, vscroll, WD_MATRIX_TOP, WID_NG_CLIENTS, WID_NG_DATE, WID_NG_DETAILS, WID_NG_INFO, WID_NG_LASTJOINED, WID_NG_MAPSIZE, WID_NG_MATRIX, WID_NG_NAME, and WID_NG_YEARS.

static int CDECL NetworkGameWindow::NGameAllowedSorter | ( | NetworkGameList *const * | a,
|  | NetworkGameList *const * | b |
| ) |  |  | `[inline, static, protected]`

Sort servers by joinability.

If both servers are the same, prefer the non-passworded server first.

Definition at line 332 of file network_gui.cpp.

References NGameClientSorter(), and StrEmpty().

static int CDECL NetworkGameWindow::NGameClientSorter | ( | NetworkGameList *const * | a,
|  | NetworkGameList *const * | b |
| ) |  |  | `[inline, static, protected]`

Sort servers by the amount of clients online on a server.

If the two servers have the same amount, the one with the higher maximum is preferred.

Definition at line 293 of file network_gui.cpp.

References NGameNameSorter().

Referenced by NGameAllowedSorter(), NGameDateSorter(), and NGameMapSizeSorter().

static int CDECL NetworkGameWindow::NGameNameSorter | ( | NetworkGameList *const * | a,
|  | NetworkGameList *const * | b |
| ) |  |  | `[inline, static, protected]`

Sort servers by name.

Definition at line 282 of file network_gui.cpp.

References SkipGarbage(), and strnatcmp().

Referenced by NGameClientSorter().

virtual void NetworkGameWindow::OnClick | ( | Point | pt,
|  | int | widget,
|  | int | click_count |
| ) |  |  | `[inline, virtual]`

A click with the left mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.
  | click_count | Number of fast consecutive clicks at same position

Reimplemented from Window.

Definition at line 690 of file network_gui.cpp.

References _settings_client, NetworkGameList::address, NetworkSettings::connect_to_ip, CS_ALPHANUMERAL, DeleteWindowById(), GUIList< T, F >::ForceResort(), NetworkAddress::GetPort(), Scrollbar::GetScrolledRowFromWidget(), NetworkGameInfo::grfconfig, NetworkGameList::info, Window::IsWidgetDisabled(), NetworkSettings::lan_internet, NetworkSettings::last_host, last_joined, NetworkSettings::last_port, SmallVector< T, S >::Length(), list_pos, ClientSettings::network, NETWORK_HOSTNAME_LENGTH, NetworkUDPQueryMasterServer(), NetworkUDPQueryServer(), NetworkUDPSearchGame(), QSF_ACCEPT_UNCHANGED, ScrollToSelectedServer(), server, servers, Window::SetDirty(), SetDParamStr(), GUIList< T, F >::SetSortType(), ShowDropDownMenu(), ShowMissingContentWindow(), ShowNetworkLobbyWindow(), ShowNewGRFSettings(), ShowQueryString(), SortNetworkGameList(), GUIList< T, F >::SortType(), GUIList< T, F >::ToggleSortOrder(), UpdateListPos(), vscroll, WC_NETWORK_WINDOW, WID_NG_ADD, WID_NG_CANCEL, WID_NG_CLIENTS, WID_NG_CONN_BTN, WID_NG_DATE, WID_NG_FIND, WID_NG_INFO, WID_NG_JOIN, WID_NG_LASTJOINED, WID_NG_MAPSIZE, WID_NG_MATRIX, WID_NG_NAME, WID_NG_NEWGRF, WID_NG_NEWGRF_MISSING, WID_NG_REFRESH, WID_NG_START, WID_NG_YEARS, and WN_NETWORK_WINDOW_GAME.

virtual void NetworkGameWindow::OnDropdownSelect | ( | int | widget,
|  | int | index |
| ) |  |  | `[inline, virtual]`

A dropdown option associated to this window has been selected.

Parameters:

  | widget | the widget (button) that the dropdown is associated with.
  | index | the element in the dropdown that is selected.

Reimplemented from Window.

Definition at line 787 of file network_gui.cpp.

References _settings_client, NetworkSettings::lan_internet, ClientSettings::network, Window::SetDirty(), and WID_NG_CONN_BTN.

virtual void NetworkGameWindow::OnEditboxChanged | ( | int | widget | ) | `[inline, virtual]`

The text in an editbox has been edited.

Parameters:

  | widget | The widget of the editbox.

Reimplemented from Window.

Definition at line 873 of file network_gui.cpp.

References _settings_client, Textbuf::buf, BuildGUINetworkGameList(), NetworkSettings::client_name, GUIList< T, F >::ForceRebuild(), lastof, name_editbox, ClientSettings::network, ScrollToSelectedServer(), servers, Window::SetDirty(), strecpy(), StrEmpty(), WID_NG_CLIENT, and WID_NG_FILTER.

virtual void NetworkGameWindow::OnInvalidateData | ( | int | data = `0`,
|  | bool | gui_scope = `true` |
| ) |  |  | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | Information about the changed data.
  | gui_scope | Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See InvalidateWindowData() for details.

Reimplemented from Window.

Definition at line 806 of file network_gui.cpp.

References GUIList< T, F >::ForceRebuild(), servers, and Window::SetDirty().

virtual EventState NetworkGameWindow::OnKeyPress | ( | uint16 | key,
|  | uint16 | keycode |
| ) |  |  | `[inline, virtual]`

A key has been pressed.

Parameters:

  | key | the Unicode value of the key.
  | keycode | the untranslated key code including shift state.

Returns:
  ES_HANDLED if the key press has been handled and no other window should receive the event.

Reimplemented from Window.

Definition at line 812 of file network_gui.cpp.

References ES_HANDLED, Scrollbar::GetCapacity(), last_joined, SmallVector< T, S >::Length(), list_pos, min(), NetworkGameListRemoveItem(), ScrollToSelectedServer(), server, servers, Window::SetDirty(), and vscroll.

virtual void NetworkGameWindow::OnPaint | ( |  | ) | `[inline, virtual]`

The window must be repainted.

Note:
  This method should not change any state, it should only use drawing functions.

Reimplemented from Window.

Definition at line 594 of file network_gui.cpp.

References BuildGUINetworkGameList(), NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::compatible, Window::DrawWidgets(), NetworkGameInfo::grfconfig, NetworkGameList::info, GUIList< T, F >::NeedRebuild(), GUIList< T, F >::NeedResort(), NetworkGameList::online, server, servers, Window::SetWidgetDisabledState(), SortNetworkGameList(), NetworkGameInfo::version_compatible, WID_NG_JOIN, and WID_NG_REFRESH.

virtual void NetworkGameWindow::OnQueryTextFinished | ( | char * | str | ) | `[inline, virtual]`

The query window opened from this window has closed.

Parameters:

  | str | the new value of the string, NULL if the window was cancelled or an empty string when the default button was pressed, i.e. StrEmpty(str).

Reimplemented from Window.

Definition at line 895 of file network_gui.cpp.

References StrEmpty().

virtual void NetworkGameWindow::OnResize | ( |  | ) | `[inline, virtual]`

Called after the window got resized.

For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.

Reimplemented from Window.

Definition at line 900 of file network_gui.cpp.

References Scrollbar::GetCapacity(), MAT_COL_START, Scrollbar::SetCapacityFromWidget(), vscroll, and WID_NG_MATRIX.

void NetworkGameWindow::ScrollToSelectedServer | ( |  | ) | `[inline, protected]`

Scroll the list up or down to the currently selected server.

If the server is below the currently displayed servers, it will scroll down an amount so that the server appears at the bottom. If the server is above the currently displayed servers, it will scroll up so that the server appears at the top.

Definition at line 454 of file network_gui.cpp.

References list_pos, Scrollbar::ScrollTowards(), and vscroll.

Referenced by OnClick(), OnEditboxChanged(), and OnKeyPress().

virtual void NetworkGameWindow::SetStringParameters | ( | int | widget | ) | const`[inline, virtual]`

Initialize string parameters for a widget.

Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.

Parameters:

  | widget | Widget number.

Reimplemented from Window.

Definition at line 493 of file network_gui.cpp.

References _settings_client, NetworkSettings::lan_internet, ClientSettings::network, SetDParam(), and WID_NG_CONN_BTN.

static const char* NetworkGameWindow::SkipGarbage | ( | const char * | str | ) | `[inline, static, protected]`

Skip some of the 'garbage' in the string that we don't want to use to sort on.

This way the alphabetical sorting will work better as we would be actually using those characters instead of some other characters such as spaces and tildes at the begin of the name.

Parameters:

  | str | The string to skip the initial garbage of.

Returns:
  The string with the garbage skipped.

Definition at line 275 of file network_gui.cpp.

References IsInsideMM().

Referenced by NGameNameSorter().

virtual void NetworkGameWindow::UpdateWidgetSize | ( | int | widget,
|  | Dimension * | size,
|  | const Dimension & | padding,
|  | Dimension * | fill,
|  | Dimension * | resize |
| ) |  |  | `[inline, virtual]`

Update size and resize step of a widget in the window.

After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.

Parameters:

  | widget | Widget number.
  | size | Size of the widget.
  | padding | Recommended amount of space between the widget content and the widget edge.
  | fill | Fill step of the widget.
  | resize | Resize step of the widget.

Reimplemented from Window.

Definition at line 502 of file network_gui.cpp.

References FONT_HEIGHT_NORMAL, GetStringBoundingBox(), MAX_CLIENTS, MAX_COMPANIES, MAX_MAP_SIZE, maxdim(), SetDParam(), WD_MATRIX_TOP, WID_NG_CLIENTS, WID_NG_CONN_BTN, WID_NG_DATE, WID_NG_DETAILS_SPACER, WID_NG_LASTJOINED, WID_NG_LASTJOINED_SPACER, WID_NG_MAPSIZE, WID_NG_MATRIX, WID_NG_NAME, and WID_NG_YEARS.

## Field Documentation

GUIGameServerList::FilterFunction *const NetworkGameWindow::filter_funcs`[static, protected]`

Initial value:

     {
      &NGameSearchFilter
    }

Definition at line 221 of file network_gui.cpp.

GUIGameServerList::SortFunction *const NetworkGameWindow::sorter_funcs`[static, protected]`

Initial value:

     {
      &NGameNameSorter,
      &NGameClientSorter,
      &NGameMapSizeSorter,
      &NGameDateSorter,
      &NGameYearsSorter,
      &NGameAllowedSorter
    }

Definition at line 220 of file network_gui.cpp.

The documentation for this class was generated from the following file:

- src/network/network_gui.cpp