# NetworkContentListWindow Class Reference

Window that lists the content that's at the content server. More...

Inheritance diagram for NetworkContentListWindow:

## Public Member Functions

| NetworkContentListWindow (const WindowDesc *desc, bool select_all)
| Create the content list window.
| ~NetworkContentListWindow ()
| Free everything we allocated.
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 | DrawMatrix (const Rect &r) const
void | DrawDetails (const Rect &r) const
| Helper function to draw the details part of this window.
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 | OnMouseLoop ()
| Called for every mouse loop run, which is at least once per (game) tick.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
virtual void | OnOSKInput (int wid)
virtual void | OnResize ()
| Called after the window got resized.
virtual void | OnReceiveContentInfo (const ContentInfo *rci)
| We received a content info.
virtual void | OnDownloadComplete (ContentID cid)
| We have finished downloading a file.
virtual void | OnConnect (bool success)
| Callback for when the connection has finished.
virtual void | OnInvalidateData (int data)
| Some data on this window has become invalid.

## Private Types

enum | { EDITBOX_MAX_SIZE = 50, EDITBOX_MAX_LENGTH = 300 }
typedef GUIList< const ContentInfo * > | GUIContentList

## Private Member Functions

void | BuildContentList ()
| (Re)build the network game list as its amount has changed because an item has been added or deleted for example
void | SortContentList ()
| Sort the content list.
void | FilterContentList ()
| Filter the content list.
void | ScrollToSelected ()
| Make sure that the currently selected content info is within the visible part of the matrix.

## Static Private Member Functions

static int CDECL | NameSorter (const ContentInfo *const *a, const ContentInfo *const *b)
| Sort content by name.
static int CDECL | TypeSorter (const ContentInfo *const *a, const ContentInfo *const *b)
| Sort content by type.
static int CDECL | StateSorter (const ContentInfo *const *a, const ContentInfo *const *b)
| Sort content by state.
static bool CDECL | TagNameFilter (const ContentInfo *const *a, const char *filter_string)
| Filter content by tags/name.

## Private Attributes

GUIContentList | content
| List with content.
const ContentInfo * | selected
| The selected content info.
int | list_pos
| Our position in the list.
uint | filesize_sum
| The sum of all selected file sizes.

## Static Private Attributes

static Listing | last_sorting = {false, 1}
| Runtime saved values.
static Filtering | last_filtering = {false, 0}
static GUIContentList::SortFunction *const | sorter_funcs []
| The sorter functions.
static GUIContentList::FilterFunction *const | filter_funcs []

## Detailed Description

Window that lists the content that's at the content server.

Definition at line 220 of file network_content_gui.cpp.

## Constructor & Destructor Documentation

NetworkContentListWindow::NetworkContentListWindow | ( | const WindowDesc * | desc,
|  | bool | select_all |
| ) |  |  | `[inline]`

Create the content list window.

Parameters:

  | desc | the window description to pass to Window's constructor.

Definition at line 346 of file network_content_gui.cpp.

References ClientNetworkContentSocketHandler::AddCallback(), content, CS_ALPHANUMERAL, QueryStringBaseWindow::edit_str_size, FilterContentList(), GUIList< T, F >::ForceRebuild(), InitializeTextBuffer(), Window::InitNested(), Window::InvalidateData(), last_sorting, NCLWW_FILTER, NCLWW_SEL_ALL_UPDATE, GUIList< T, F >::SetFilterFuncs(), GUIList< T, F >::SetFiltering(), Window::SetFocusedWidget(), GUIList< T, F >::SetListing(), GUIList< T, F >::SetSortFuncs(), SortContentList(), and sorter_funcs.

## Member Function Documentation

void NetworkContentListWindow::DrawDetails | ( | const Rect & | r | ) | const`[inline]`

Helper function to draw the details part of this window.

Parameters:

  | r | the rectangle to stay within while drawing

< Number of pixels at the left

< Number of pixels at the right

< Number of pixels at the top

Definition at line 477 of file network_content_gui.cpp.

References SmallVector< T, S >::Begin(), ClientNetworkContentSocketHandler::Begin(), CONTENT_TYPE_BASE_GRAPHICS, ContentInfo::dependencies, ContentInfo::dependency_count, ContentInfo::description, DrawString(), DrawStringMultiLine(), SmallVector< T, S >::End(), ClientNetworkContentSocketHandler::End(), ContentInfo::filesize, filesize_sum, FONT_HEIGHT_NORMAL, GfxFillRect(), ContentInfo::id, ContentInfo::IsSelected(), lastof, ContentInfo::name, ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(), SA_CENTER, ContentInfo::SELECTED, selected, seprintf(), SetDParam(), SetDParamStr(), ContentInfo::state, StrEmpty(), ContentInfo::tag_count, ContentInfo::tags, ContentInfo::type, ContentInfo::upgrade, ContentInfo::url, ContentInfo::version, WD_INSET_LEFT, WD_INSET_RIGHT, WD_INSET_TOP, WD_PAR_VSEP_NORMAL, and WD_PAR_VSEP_WIDE.

Referenced by DrawWidget().

virtual void NetworkContentListWindow::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 400 of file network_content_gui.cpp.

References DrawDetails(), DrawString(), NCLWW_DETAILS, NCLWW_FILTER_CAPT, NCLWW_MATRIX, and SA_RIGHT.

static int CDECL NetworkContentListWindow::NameSorter | ( | const ContentInfo *const * | a,
|  | const ContentInfo *const * | b |
| ) |  |  | `[inline, static, private]`

Sort content by name.

Definition at line 265 of file network_content_gui.cpp.

Referenced by TypeSorter().

virtual void NetworkContentListWindow::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 586 of file network_content_gui.cpp.

References BringWindowToFrontById(), content, NWidgetBase::current_x, GUIList< T, F >::ForceResort(), SmallVector< T, S >::Get(), Scrollbar::GetCapacity(), Scrollbar::GetPosition(), Window::InvalidateData(), IsInsideBS(), SmallVector< T, S >::Length(), list_pos, NCLWW_CANCEL, NCLWW_CHECKBOX, NCLWW_DOWNLOAD, NCLWW_MATRIX, NCLWW_NAME, NCLWW_SELECT_ALL, NCLWW_SELECT_UPDATE, NCLWW_TYPE, NCLWW_UNSELECT, NWidgetBase::pos_x, Window::resize, ScrollToSelected(), ClientNetworkContentSocketHandler::SelectAll(), selected, ClientNetworkContentSocketHandler::SelectUpgrade(), GUIList< T, F >::SetSortType(), SortContentList(), GUIList< T, F >::SortType(), ResizeInfo::step_height, ClientNetworkContentSocketHandler::ToggleSelectedState(), GUIList< T, F >::ToggleSortOrder(), ClientNetworkContentSocketHandler::UnselectAll(), and Window::vscroll.

virtual void NetworkContentListWindow::OnConnect | ( | bool | success | ) | `[inline, virtual]`

Callback for when the connection has finished.

Parameters:

  | success | whether the connection was made or that we failed to make it

Reimplemented from ContentCallback.

Definition at line 742 of file network_content_gui.cpp.

References INVALID_STRING_ID, Window::InvalidateData(), and ShowErrorMessage().

virtual void NetworkContentListWindow::OnDownloadComplete | ( | ContentID | cid | ) | `[inline, virtual]`

We have finished downloading a file.

Parameters:

  | cid | the ContentID of the downloaded file

Reimplemented from ContentCallback.

Definition at line 736 of file network_content_gui.cpp.

References content, GUIList< T, F >::ForceResort(), and Window::InvalidateData().

virtual void NetworkContentListWindow::OnInvalidateData | ( | int | data | ) | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | information about the changed data.

Reimplemented from Window.

Definition at line 753 of file network_content_gui.cpp.

References ContentInfo::AUTOSELECTED, SmallVector< T, S >::Begin(), BuildContentList(), content, SmallVector< T, S >::End(), ContentInfo::filesize, filesize_sum, FindWindowById(), NCLWW_CANCEL, NCLWW_DOWNLOAD, NCLWW_SELECT_ALL, NCLWW_SELECT_UPDATE, NCLWW_UNSELECT, GUIList< T, F >::NeedRebuild(), ContentInfo::SELECTED, Window::SetWidgetDisabledState(), ContentInfo::state, ContentInfo::UNSELECTED, and ContentInfo::upgrade.

virtual EventState NetworkContentListWindow::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 654 of file network_content_gui.cpp.

References content, Window::ES_HANDLED, Window::ES_NOT_HANDLED, GUIList< T, F >::ForceResort(), SmallVector< T, S >::Get(), Scrollbar::GetCapacity(), Window::InvalidateData(), Window::IsWidgetFocused(), ClientNetworkContentSocketHandler::Length(), SmallVector< T, S >::Length(), list_pos, min(), NCLWW_FILTER, ScrollToSelected(), selected, ClientNetworkContentSocketHandler::ToggleSelectedState(), and Window::vscroll.

virtual void NetworkContentListWindow::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 417 of file network_content_gui.cpp.

References BuildContentList(), content, Window::DrawSortButtonState(), Window::DrawWidgets(), GUIList< T, F >::IsDescSortOrder(), NCLWW_CHECKBOX, NCLWW_FILTER, NCLWW_NAME, NCLWW_TYPE, GUIList< T, F >::NeedRebuild(), SBS_DOWN, SBS_UP, and GUIList< T, F >::SortType().

virtual void NetworkContentListWindow::OnReceiveContentInfo | ( | const ContentInfo * | ci | ) | `[inline, virtual]`

We received a content info.

Parameters:

  | ci | the content info

Reimplemented from ContentCallback.

Definition at line 730 of file network_content_gui.cpp.

References content, GUIList< T, F >::ForceRebuild(), and Window::InvalidateData().

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

Called after the window got resized.

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

Reimplemented from Window.

Definition at line 724 of file network_content_gui.cpp.

References Scrollbar::GetCapacity(), MAT_COL_START, MAT_ROW_START, NCLWW_MATRIX, Scrollbar::SetCapacityFromWidget(), and Window::vscroll.

static int CDECL NetworkContentListWindow::StateSorter | ( | const ContentInfo *const * | a,
|  | const ContentInfo *const * | b |
| ) |  |  | `[inline, static, private]`

Sort content by state.

Definition at line 286 of file network_content_gui.cpp.

References TypeSorter().

static int CDECL NetworkContentListWindow::TypeSorter | ( | const ContentInfo *const * | a,
|  | const ContentInfo *const * | b |
| ) |  |  | `[inline, static, private]`

Sort content by type.

Definition at line 271 of file network_content_gui.cpp.

References CONTENT_TYPE_BASE_GRAPHICS, lastof, and NameSorter().

Referenced by StateSorter().

virtual void NetworkContentListWindow::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 376 of file network_content_gui.cpp.

References CONTENT_TYPE_BASE_GRAPHICS, CONTENT_TYPE_BEGIN, CONTENT_TYPE_END, FONT_HEIGHT_NORMAL, GetStringBoundingBox(), maxdim(), NCLWW_FILTER_CAPT, NCLWW_MATRIX, NCLWW_TYPE, WD_MATRIX_BOTTOM, WD_MATRIX_LEFT, WD_MATRIX_RIGHT, and WD_MATRIX_TOP.

## Field Documentation

NetworkContentListWindow::GUIContentList::FilterFunction *const NetworkContentListWindow::filter_funcs`[static, private]`

Initial value:

     {
      &TagNameFilter,
    }

Definition at line 233 of file network_content_gui.cpp.

NetworkContentListWindow::GUIContentList::SortFunction *const NetworkContentListWindow::sorter_funcs`[static, private]`

Initial value:

     {
      &StateSorter,
      &TypeSorter,
      &NameSorter,
    }

The sorter functions.

Definition at line 232 of file network_content_gui.cpp.

Referenced by NetworkContentListWindow().

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

- src/network/network_content_gui.cpp