Window that lists the content that's at the content server. More...
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 |
Draw/fill the matrix with the list of content to download. | |
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) |
Callback for when on input has been entered with the OSK. | |
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=0, bool gui_scope=true) |
Some data on this window has become invalid. | |
Private Types | |
typedef GUIList< const ContentInfo * > | GUIContentList |
List with content infos. | |
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. | |
Scrollbar * | vscroll |
Cache of the vertical scrollbar. | |
Static Private Attributes | |
static const uint | EDITBOX_MAX_SIZE = 50 |
Maximum size of the editbox in characters. | |
static const uint | EDITBOX_MAX_LENGTH = 300 |
Maximum size of the editbox in pixels. | |
static Listing | last_sorting = {false, 1} |
The last sorting setting. | |
static Filtering | last_filtering = {false, 0} |
The last filtering setting. | |
static GUIContentList::SortFunction *const | sorter_funcs [] |
Sorter functions. | |
static GUIContentList::FilterFunction *const | filter_funcs [] |
Filter functions. |
Window that lists the content that's at the content server.
Definition at line 222 of file network_content_gui.cpp.
typedef GUIList<const ContentInfo*> NetworkContentListWindow::GUIContentList [private] |
List with content infos.
Definition at line 224 of file network_content_gui.cpp.
NetworkContentListWindow::NetworkContentListWindow | ( | const WindowDesc * | desc, | |
bool | select_all | |||
) | [inline] |
Create the content list window.
desc | the window description to pass to Window's constructor. | |
select_all | Whether the select all button is allowed or not. |
Definition at line 347 of file network_content_gui.cpp.
References _network_content_client, ClientNetworkContentSocketHandler::AddCallback(), content, Window::CreateNestedTree(), CS_ALPHANUMERAL, QueryStringBaseWindow::edit_str_buf, QueryStringBaseWindow::edit_str_size, EDITBOX_MAX_LENGTH, filter_funcs, FilterContentList(), Window::FinishInitNested(), GUIList< T, F >::ForceRebuild(), Window::GetScrollbar(), InitializeTextBuffer(), Window::InvalidateData(), last_filtering, last_sorting, NCLWW_FILTER, NCLWW_SCROLLBAR, NCLWW_SEL_ALL_UPDATE, GUIList< T, F >::SetFilterFuncs(), GUIList< T, F >::SetFiltering(), Window::SetFocusedWidget(), GUIList< T, F >::SetListing(), GUIList< T, F >::SetSortFuncs(), SortContentList(), sorter_funcs, and vscroll.
void NetworkContentListWindow::DrawDetails | ( | const Rect & | r | ) | const [inline] |
Helper function to draw the details part of this window.
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 484 of file network_content_gui.cpp.
References _network_content_client, SmallVector< T, S >::Begin(), ClientNetworkContentSocketHandler::Begin(), CONTENT_TYPE_BASE_GRAPHICS, ContentInfo::dependencies, ContentInfo::dependency_count, ContentInfo::description, DRAW_STRING_BUFFER, DrawString(), DrawStringMultiLine(), SmallVector< T, S >::End(), ClientNetworkContentSocketHandler::End(), ContentInfo::filesize, filesize_sum, FONT_HEIGHT_NORMAL, GfxFillRect(), ContentInfo::id, ContentInfo::IsSelected(), lastof, ContentInfo::name, PC_DARK_BLUE, ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(), SA_CENTER, SA_HOR_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().
void NetworkContentListWindow::DrawMatrix | ( | const Rect & | r | ) | const [inline] |
Draw/fill the matrix with the list of content to download.
r | The boundaries of the matrix. |
Definition at line 444 of file network_content_gui.cpp.
References ContentInfo::ALREADY_HERE, ContentInfo::AUTOSELECTED, content, CONTENT_TYPE_BASE_GRAPHICS, ContentInfo::DOES_NOT_EXIST, DrawSprite(), DrawString(), SmallVector< T, S >::End(), FONT_HEIGHT_NORMAL, SmallVector< T, S >::Get(), Scrollbar::GetCapacity(), GfxFillRect(), ContentInfo::name, NCLWW_CHECKBOX, NCLWW_NAME, NCLWW_TYPE, PC_GREY, NWidgetBase::pos_x, Window::resize, SA_HOR_CENTER, ContentInfo::SELECTED, selected, ContentInfo::state, ResizeInfo::step_height, ContentInfo::type, ContentInfo::UNSELECTED, vscroll, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, and WD_MATRIX_TOP.
Referenced by DrawWidget().
virtual void NetworkContentListWindow::DrawWidget | ( | const Rect & | r, | |
int | widget | |||
) | const [inline, virtual] |
Draw the contents of a nested widget.
r | Rectangle occupied by the widget. | |
widget | Number of the widget to draw. |
Reimplemented from Window.
Definition at line 403 of file network_content_gui.cpp.
References DrawDetails(), DrawMatrix(), 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.
References strnatcmp().
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.
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 593 of file network_content_gui.cpp.
References _network_content_client, BringWindowToFrontById(), content, NWidgetBase::current_x, GUIList< T, F >::ForceResort(), SmallVector< T, S >::Get(), Scrollbar::GetScrolledRowFromWidget(), 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, ScrollToSelected(), ClientNetworkContentSocketHandler::SelectAll(), selected, ClientNetworkContentSocketHandler::SelectUpgrade(), GUIList< T, F >::SetSortType(), SortContentList(), GUIList< T, F >::SortType(), ClientNetworkContentSocketHandler::ToggleSelectedState(), GUIList< T, F >::ToggleSortOrder(), ClientNetworkContentSocketHandler::UnselectAll(), and vscroll.
virtual void NetworkContentListWindow::OnConnect | ( | bool | success | ) | [inline, virtual] |
Callback for when the connection has finished.
success | whether the connection was made or that we failed to make it |
Reimplemented from ContentCallback.
Definition at line 746 of file network_content_gui.cpp.
References INVALID_STRING_ID, Window::InvalidateData(), ShowErrorMessage(), and WL_ERROR.
virtual void NetworkContentListWindow::OnDownloadComplete | ( | ContentID | cid | ) | [inline, virtual] |
We have finished downloading a file.
cid | the ContentID of the downloaded file |
Reimplemented from ContentCallback.
Definition at line 740 of file network_content_gui.cpp.
References content, GUIList< T, F >::ForceResort(), and Window::InvalidateData().
virtual void NetworkContentListWindow::OnInvalidateData | ( | int | data = 0 , |
|
bool | gui_scope = true | |||
) | [inline, virtual] |
Some data on this window has become invalid.
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 762 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.
key | the Unicode value of the key. | |
keycode | the untranslated key code including shift state. |
Reimplemented from Window.
Definition at line 658 of file network_content_gui.cpp.
References _network_content_client, content, ES_HANDLED, 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, OnOSKInput(), ScrollToSelected(), selected, ClientNetworkContentSocketHandler::ToggleSelectedState(), and vscroll.
virtual void NetworkContentListWindow::OnOSKInput | ( | int | wid | ) | [inline, virtual] |
Callback for when on input has been entered with the OSK.
wid | The widget the OSK was attached to. |
Reimplemented from QueryStringBaseWindow.
Definition at line 721 of file network_content_gui.cpp.
References content, QueryStringBaseWindow::edit_str_buf, GUIList< T, F >::ForceRebuild(), Window::InvalidateData(), GUIList< T, F >::SetFilterState(), and StrEmpty().
Referenced by OnKeyPress().
virtual void NetworkContentListWindow::OnPaint | ( | ) | [inline, virtual] |
The window must be repainted.
Reimplemented from Window.
Definition at line 420 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.
ci | the content info |
Reimplemented from ContentCallback.
Definition at line 734 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 728 of file network_content_gui.cpp.
References Scrollbar::GetCapacity(), MAT_COL_START, MAT_ROW_START, NCLWW_MATRIX, Scrollbar::SetCapacityFromWidget(), and 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, NameSorter(), and strnatcmp().
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.
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 379 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.
NetworkContentListWindow::GUIContentList::FilterFunction *const NetworkContentListWindow::filter_funcs [static, private] |
{ &TagNameFilter, }
Filter functions.
Definition at line 232 of file network_content_gui.cpp.
Referenced by NetworkContentListWindow().
NetworkContentListWindow::GUIContentList::SortFunction *const NetworkContentListWindow::sorter_funcs [static, private] |
{ &StateSorter, &TypeSorter, &NameSorter, }
Sorter functions.
Definition at line 231 of file network_content_gui.cpp.
Referenced by NetworkContentListWindow().