2009-01-17 16:53:32 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-06-01 12:56:18 +00:00
|
|
|
/** @file network_content_gui.cpp Implementation of the Network Content related GUIs. */
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
#include "../stdafx.h"
|
|
|
|
#include "../strings_func.h"
|
|
|
|
#include "../gfx_func.h"
|
|
|
|
#include "../window_func.h"
|
|
|
|
#include "../gui.h"
|
|
|
|
#include "../ai/ai.hpp"
|
2009-08-09 16:54:03 +00:00
|
|
|
#include "../base_media_base.h"
|
2009-01-22 14:15:52 +00:00
|
|
|
#include "../sortlist_type.h"
|
2009-02-06 12:00:14 +00:00
|
|
|
#include "../querystring_gui.h"
|
2009-01-17 16:53:32 +00:00
|
|
|
#include "network_content.h"
|
|
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
#include "../table/sprites.h"
|
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
/** Widgets used by this window */
|
|
|
|
enum DownloadStatusWindowWidgets {
|
|
|
|
NCDSWW_CAPTION, ///< Caption of the window
|
|
|
|
NCDSWW_BACKGROUND, ///< Background
|
|
|
|
NCDSWW_CANCELOK, ///< Cancel/OK button
|
|
|
|
};
|
|
|
|
|
2009-05-05 20:08:50 +00:00
|
|
|
/** Nested widgets for the download window. */
|
|
|
|
static const NWidgetPart _nested_network_content_download_status_window_widgets[] = {
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, NCDSWW_CAPTION), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, NCDSWW_BACKGROUND),
|
2009-11-17 17:51:44 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(350, 0), SetMinimalTextLines(3, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 30),
|
2009-05-05 20:08:50 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(125, 0),
|
2009-08-05 17:59:21 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCDSWW_CANCELOK), SetMinimalSize(101, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
/** Window description for the download window */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _network_content_download_status_window_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 350, 85,
|
2009-01-17 16:53:32 +00:00
|
|
|
WC_NETWORK_STATUS_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_MODAL,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_network_content_download_status_window_widgets, lengthof(_nested_network_content_download_status_window_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
/** Window for showing the download status of content */
|
|
|
|
struct NetworkContentDownloadStatusWindow : public Window, ContentCallback {
|
|
|
|
private:
|
|
|
|
ClientNetworkContentSocketHandler *connection; ///< Our connection with the content server
|
|
|
|
SmallVector<ContentType, 4> receivedTypes; ///< Types we received so we can update their cache
|
|
|
|
|
|
|
|
uint total_files; ///< Number of files to download
|
|
|
|
uint downloaded_files; ///< Number of files downloaded
|
|
|
|
uint total_bytes; ///< Number of bytes to download
|
|
|
|
uint downloaded_bytes; ///< Number of bytes downloaded
|
|
|
|
|
|
|
|
uint32 cur_id; ///< The current ID of the downloaded file
|
2009-01-18 15:53:21 +00:00
|
|
|
char name[48]; ///< The current name of the downloaded file
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new download window based on a list of content information
|
|
|
|
* with flags whether to download them or not.
|
|
|
|
* @param infos the list to search in
|
|
|
|
*/
|
2009-01-20 16:51:55 +00:00
|
|
|
NetworkContentDownloadStatusWindow() :
|
2009-01-17 16:53:32 +00:00
|
|
|
cur_id(UINT32_MAX)
|
|
|
|
{
|
|
|
|
this->parent = FindWindowById(WC_NETWORK_WINDOW, 1);
|
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.AddCallback(this);
|
|
|
|
_network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-07-16 16:48:16 +00:00
|
|
|
this->InitNested(&_network_content_download_status_window_desc, 0);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Free whatever we've allocated */
|
|
|
|
~NetworkContentDownloadStatusWindow()
|
|
|
|
{
|
|
|
|
/* Tell all the backends about what we've downloaded */
|
|
|
|
for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
|
|
|
|
switch (*iter) {
|
|
|
|
case CONTENT_TYPE_AI:
|
|
|
|
case CONTENT_TYPE_AI_LIBRARY:
|
|
|
|
AI::Rescan();
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowClassesDirty(WC_AI_DEBUG);
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_TYPE_BASE_GRAPHICS:
|
2009-08-09 16:54:03 +00:00
|
|
|
BaseGraphics::FindSets();
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_GAME_OPTIONS, 0);
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-09 19:50:44 +00:00
|
|
|
case CONTENT_TYPE_BASE_SOUNDS:
|
|
|
|
BaseSounds::FindSets();
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_GAME_OPTIONS, 0);
|
2009-08-09 19:50:44 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
case CONTENT_TYPE_NEWGRF:
|
|
|
|
ScanNewGRFFiles();
|
|
|
|
/* Yes... these are the NewGRF windows */
|
2009-09-13 16:43:16 +00:00
|
|
|
InvalidateWindowClassesData(WC_SAVELOAD);
|
2009-01-17 16:53:32 +00:00
|
|
|
InvalidateWindowData(WC_GAME_OPTIONS, 0, 1);
|
2009-03-19 17:56:45 +00:00
|
|
|
InvalidateWindowData(WC_NETWORK_WINDOW, 1, 2);
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-06 19:33:45 +00:00
|
|
|
case CONTENT_TYPE_SCENARIO:
|
|
|
|
case CONTENT_TYPE_HEIGHTMAP:
|
|
|
|
extern void ScanScenarios();
|
|
|
|
ScanScenarios();
|
2009-03-13 21:32:38 +00:00
|
|
|
InvalidateWindowData(WC_SAVELOAD, 0, 0);
|
2009-03-06 19:33:45 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.RemoveCallback(this);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2009-07-16 16:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (widget != NCDSWW_BACKGROUND) return;
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
/* Draw nice progress bar :) */
|
2009-11-17 17:51:44 +00:00
|
|
|
DrawFrameRect(r.left + 20, r.top + 4, r.left + 20 + (int)((this->width - 40LL) * this->downloaded_bytes / this->total_bytes), r.top + 14, COLOUR_MAUVE, FR_NONE);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-11-17 17:51:44 +00:00
|
|
|
int y = r.top + 20;
|
2009-01-17 16:53:32 +00:00
|
|
|
SetDParam(0, this->downloaded_bytes);
|
|
|
|
SetDParam(1, this->total_bytes);
|
2009-04-17 17:48:33 +00:00
|
|
|
SetDParam(2, this->downloaded_bytes * 100LL / this->total_bytes);
|
2009-11-17 17:51:44 +00:00
|
|
|
DrawString(r.left + 2, r.right - 2, y, STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, TC_FROMSTRING, SA_CENTER);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-11-17 17:51:44 +00:00
|
|
|
StringID str;
|
2009-07-16 16:48:16 +00:00
|
|
|
if (this->downloaded_bytes == this->total_bytes) {
|
2009-11-17 17:51:44 +00:00
|
|
|
str = STR_CONTENT_DOWNLOAD_COMPLETE;
|
2009-01-17 16:53:32 +00:00
|
|
|
} else if (!StrEmpty(this->name)) {
|
|
|
|
SetDParamStr(0, this->name);
|
|
|
|
SetDParam(1, this->downloaded_files);
|
|
|
|
SetDParam(2, this->total_files);
|
2009-11-17 17:51:44 +00:00
|
|
|
str = STR_CONTENT_DOWNLOAD_FILE;
|
2009-01-17 16:53:32 +00:00
|
|
|
} else {
|
2009-11-17 17:51:44 +00:00
|
|
|
str = STR_CONTENT_DOWNLOAD_INITIALISE;
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
2009-11-17 17:51:44 +00:00
|
|
|
|
|
|
|
y += FONT_HEIGHT_NORMAL + 5;
|
|
|
|
DrawStringMultiLine(r.left + 2, r.right - 2, y, y + FONT_HEIGHT_NORMAL * 2, str, TC_FROMSTRING, SA_CENTER);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2009-01-22 14:15:52 +00:00
|
|
|
if (widget == NCDSWW_CANCELOK) {
|
|
|
|
if (this->downloaded_bytes != this->total_bytes) _network_content_client.Close();
|
2009-01-22 10:09:56 +00:00
|
|
|
delete this;
|
|
|
|
}
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes)
|
2009-01-17 16:53:32 +00:00
|
|
|
{
|
|
|
|
if (ci->id != this->cur_id) {
|
|
|
|
strecpy(this->name, ci->filename, lastof(this->name));
|
|
|
|
this->cur_id = ci->id;
|
|
|
|
this->downloaded_files++;
|
|
|
|
this->receivedTypes.Include(ci->type);
|
|
|
|
}
|
|
|
|
this->downloaded_bytes += bytes;
|
|
|
|
|
2009-07-16 16:48:16 +00:00
|
|
|
/* When downloading is finished change cancel in ok */
|
|
|
|
if (this->downloaded_bytes == this->total_bytes) {
|
2009-09-19 11:31:12 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NCDSWW_CANCELOK)->widget_data = STR_BUTTON_OK;
|
2009-07-16 16:48:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
/** Widgets of the content list window. */
|
|
|
|
enum NetworkContentListWindowWidgets {
|
|
|
|
NCLWW_CLOSE, ///< Close 'X' button
|
|
|
|
NCLWW_CAPTION, ///< Caption of the window
|
|
|
|
NCLWW_BACKGROUND, ///< Resize button
|
2009-01-22 14:15:52 +00:00
|
|
|
|
2009-10-22 16:45:29 +00:00
|
|
|
NCLWW_FILTER_CAPT, ///< Caption for the filter editbox
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_FILTER, ///< Filter editbox
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_CHECKBOX, ///< Button above checkboxes
|
|
|
|
NCLWW_TYPE, ///< 'Type' button
|
|
|
|
NCLWW_NAME, ///< 'Name' button
|
2009-02-06 12:00:14 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_MATRIX, ///< Panel with list of content
|
|
|
|
NCLWW_SCROLLBAR, ///< Scrollbar of matrix
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_DETAILS, ///< Panel with content details
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_SELECT_ALL, ///< 'Select all' button
|
|
|
|
NCLWW_SELECT_UPDATE, ///< 'Select updates' button
|
|
|
|
NCLWW_UNSELECT, ///< 'Unselect all' button
|
|
|
|
NCLWW_CANCEL, ///< 'Cancel' button
|
|
|
|
NCLWW_DOWNLOAD, ///< 'Download' button
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
NCLWW_RESIZE, ///< Resize button
|
2009-10-22 16:45:29 +00:00
|
|
|
|
|
|
|
NCLWW_SEL_ALL_UPDATE, ///< #NWID_SELECTION widget for select all/update buttons.
|
2009-05-05 20:07:33 +00:00
|
|
|
};
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-05-05 20:07:33 +00:00
|
|
|
/** Window that lists the content that's at the content server */
|
|
|
|
class NetworkContentListWindow : public QueryStringBaseWindow, ContentCallback {
|
|
|
|
typedef GUIList<const ContentInfo*> GUIContentList;
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
enum {
|
|
|
|
EDITBOX_MAX_SIZE = 50,
|
|
|
|
EDITBOX_MAX_LENGTH = 300,
|
|
|
|
};
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
/** Runtime saved values */
|
|
|
|
static Listing last_sorting;
|
2009-02-06 12:00:14 +00:00
|
|
|
static Filtering last_filtering;
|
2009-01-22 14:15:52 +00:00
|
|
|
/** The sorter functions */
|
|
|
|
static GUIContentList::SortFunction * const sorter_funcs[];
|
2009-02-06 12:00:14 +00:00
|
|
|
static GUIContentList::FilterFunction * const filter_funcs[];
|
2009-01-22 14:15:52 +00:00
|
|
|
GUIContentList content; ///< List with content
|
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
const ContentInfo *selected; ///< The selected content info
|
|
|
|
int list_pos; ///< Our position in the list
|
2009-10-22 13:57:39 +00:00
|
|
|
uint filesize_sum; ///< The sum of all selected file sizes
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
/**
|
|
|
|
* (Re)build the network game list as its amount has changed because
|
|
|
|
* an item has been added or deleted for example
|
|
|
|
*/
|
|
|
|
void BuildContentList()
|
|
|
|
{
|
|
|
|
if (!this->content.NeedRebuild()) return;
|
|
|
|
|
|
|
|
/* Create temporary array of games to use for listing */
|
|
|
|
this->content.Clear();
|
|
|
|
|
|
|
|
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
|
|
|
|
*this->content.Append() = *iter;
|
|
|
|
}
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
this->FilterContentList();
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.Compact();
|
|
|
|
this->content.RebuildDone();
|
2009-09-13 14:50:52 +00:00
|
|
|
this->SortContentList();
|
2009-09-02 08:08:30 +00:00
|
|
|
|
|
|
|
this->vscroll.SetCount(this->content.Length()); // Update the scrollbar
|
2009-09-13 14:50:52 +00:00
|
|
|
this->ScrollToSelected();
|
2009-01-22 14:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort content by name. */
|
|
|
|
static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
|
|
|
{
|
|
|
|
return strcasecmp((*a)->name, (*b)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort content by type. */
|
|
|
|
static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
if ((*a)->type != (*b)->type) {
|
|
|
|
char a_str[64];
|
|
|
|
char b_str[64];
|
|
|
|
GetString(a_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*a)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(a_str));
|
|
|
|
GetString(b_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*b)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(b_str));
|
|
|
|
r = strcasecmp(a_str, b_str);
|
|
|
|
}
|
|
|
|
if (r == 0) r = NameSorter(a, b);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort content by state. */
|
|
|
|
static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
|
|
|
{
|
|
|
|
int r = (*a)->state - (*b)->state;
|
|
|
|
if (r == 0) r = TypeSorter(a, b);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort the content list */
|
|
|
|
void SortContentList()
|
|
|
|
{
|
|
|
|
if (!this->content.Sort()) return;
|
|
|
|
|
|
|
|
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
|
|
|
|
if (*iter == this->selected) {
|
|
|
|
this->list_pos = iter - this->content.Begin();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
/** Filter content by tags/name */
|
|
|
|
static bool CDECL TagNameFilter(const ContentInfo * const *a, const char *filter_string)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < (*a)->tag_count; i++) {
|
|
|
|
if (strcasestr((*a)->tags[i], filter_string) != NULL) return true;
|
|
|
|
}
|
|
|
|
return strcasestr((*a)->name, filter_string) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Filter the content list */
|
|
|
|
void FilterContentList()
|
|
|
|
{
|
|
|
|
if (!this->content.Filter(this->edit_str_buf)) return;
|
|
|
|
|
2009-02-06 18:00:05 +00:00
|
|
|
/* update list position */
|
2009-02-06 12:00:14 +00:00
|
|
|
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
|
|
|
|
if (*iter == this->selected) {
|
|
|
|
this->list_pos = iter - this->content.Begin();
|
2009-02-06 18:00:05 +00:00
|
|
|
return;
|
2009-02-06 12:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-06 18:00:05 +00:00
|
|
|
|
|
|
|
/* previously selected item not in list anymore */
|
|
|
|
this->selected = NULL;
|
|
|
|
this->list_pos = 0;
|
2009-02-06 12:00:14 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
/** Make sure that the currently selected content info is within the visible part of the matrix */
|
|
|
|
void ScrollToSelected()
|
|
|
|
{
|
|
|
|
if (this->selected == NULL) return;
|
|
|
|
|
2009-09-02 08:08:30 +00:00
|
|
|
this->vscroll.ScrollTowards(this->list_pos);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create the content list window.
|
|
|
|
* @param desc the window description to pass to Window's constructor.
|
|
|
|
*/
|
2009-10-22 16:45:29 +00:00
|
|
|
NetworkContentListWindow(const WindowDesc *desc, bool select_all) :
|
|
|
|
QueryStringBaseWindow(EDITBOX_MAX_SIZE),
|
|
|
|
selected(NULL),
|
|
|
|
list_pos(0)
|
2009-01-17 16:53:32 +00:00
|
|
|
{
|
2009-10-22 16:45:29 +00:00
|
|
|
this->InitNested(desc, 1);
|
|
|
|
|
|
|
|
this->GetWidget<NWidgetStacked>(NCLWW_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
this->afilter = CS_ALPHANUMERAL;
|
|
|
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
|
2009-02-09 01:22:29 +00:00
|
|
|
this->SetFocusedWidget(NCLWW_FILTER);
|
2009-02-06 12:00:14 +00:00
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.AddCallback(this);
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.SetListing(this->last_sorting);
|
2009-02-06 12:00:14 +00:00
|
|
|
this->content.SetFiltering(this->last_filtering);
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.SetSortFuncs(this->sorter_funcs);
|
2009-02-06 12:00:14 +00:00
|
|
|
this->content.SetFilterFuncs(this->filter_funcs);
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.ForceRebuild();
|
2009-02-06 12:00:14 +00:00
|
|
|
this->FilterContentList();
|
2009-01-22 14:15:52 +00:00
|
|
|
this->SortContentList();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Free everything we allocated */
|
|
|
|
~NetworkContentListWindow()
|
|
|
|
{
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.RemoveCallback(this);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-10-22 16:45:29 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case NCLWW_FILTER_CAPT:
|
|
|
|
*size = maxdim(*size, GetStringBoundingBox(STR_CONTENT_FILTER_TITLE));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_TYPE: {
|
|
|
|
Dimension d = *size;
|
|
|
|
for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS));
|
|
|
|
}
|
|
|
|
size->width = d.width + WD_MATRIX_RIGHT + WD_MATRIX_LEFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NCLWW_MATRIX:
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
size->height = 10 * resize->height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case NCLWW_FILTER_CAPT:
|
|
|
|
DrawString(r.left, r.right, r.top, STR_CONTENT_FILTER_TITLE, TC_FROMSTRING, SA_RIGHT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_DETAILS:
|
|
|
|
this->DrawDetails(r);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_MATRIX:
|
|
|
|
this->DrawMatrix(r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-01-22 14:15:52 +00:00
|
|
|
const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
|
|
|
|
|
|
|
|
if (this->content.NeedRebuild()) {
|
|
|
|
this->BuildContentList();
|
|
|
|
}
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
this->DrawWidgets();
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
/* Edit box to filter for keywords */
|
|
|
|
this->DrawEditBox(NCLWW_FILTER);
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
switch (this->content.SortType()) {
|
|
|
|
case NCLWW_CHECKBOX - NCLWW_CHECKBOX: this->DrawSortButtonState(NCLWW_CHECKBOX, arrow); break;
|
|
|
|
case NCLWW_TYPE - NCLWW_CHECKBOX: this->DrawSortButtonState(NCLWW_TYPE, arrow); break;
|
|
|
|
case NCLWW_NAME - NCLWW_CHECKBOX: this->DrawSortButtonState(NCLWW_NAME, arrow); break;
|
|
|
|
}
|
2009-10-22 16:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawMatrix(const Rect &r) const
|
|
|
|
{
|
2009-11-22 13:22:53 +00:00
|
|
|
const NWidgetBase *nwi_checkbox = this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX);
|
|
|
|
const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(NCLWW_NAME);
|
|
|
|
const NWidgetBase *nwi_type = this->GetWidget<NWidgetBase>(NCLWW_TYPE);
|
2009-10-22 16:45:29 +00:00
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
/* Fill the matrix with the information */
|
2009-11-22 19:27:51 +00:00
|
|
|
int sprite_y_offset = WD_MATRIX_TOP + (FONT_HEIGHT_NORMAL - 10) / 2;
|
2009-10-22 16:45:29 +00:00
|
|
|
uint y = r.top;
|
2009-01-17 16:53:32 +00:00
|
|
|
int cnt = 0;
|
2009-09-02 08:08:30 +00:00
|
|
|
for (ConstContentIterator iter = this->content.Get(this->vscroll.GetPosition()); iter != this->content.End() && cnt < this->vscroll.GetCapacity(); iter++, cnt++) {
|
2009-01-17 16:53:32 +00:00
|
|
|
const ContentInfo *ci = *iter;
|
|
|
|
|
2009-11-15 14:01:45 +00:00
|
|
|
if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, 10);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
SpriteID sprite;
|
|
|
|
SpriteID pal = PAL_NONE;
|
|
|
|
switch (ci->state) {
|
|
|
|
case ContentInfo::UNSELECTED: sprite = SPR_BOX_EMPTY; break;
|
|
|
|
case ContentInfo::SELECTED: sprite = SPR_BOX_CHECKED; break;
|
|
|
|
case ContentInfo::AUTOSELECTED: sprite = SPR_BOX_CHECKED; break;
|
|
|
|
case ContentInfo::ALREADY_HERE: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
|
|
|
|
case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2009-11-22 19:27:51 +00:00
|
|
|
DrawSprite(sprite, pal, nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0));
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
|
2009-11-15 14:01:45 +00:00
|
|
|
DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + WD_MATRIX_TOP, str, TC_BLACK, SA_CENTER);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-11-15 14:01:45 +00:00
|
|
|
DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + WD_MATRIX_TOP, ci->name, TC_BLACK);
|
2009-01-17 16:53:32 +00:00
|
|
|
y += this->resize.step_height;
|
|
|
|
}
|
2009-10-22 14:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to draw the details part of this window.
|
|
|
|
* @param r the rectangle to stay within while drawing
|
|
|
|
*/
|
2009-10-22 16:45:29 +00:00
|
|
|
void DrawDetails(const Rect &r) const
|
2009-10-22 14:26:18 +00:00
|
|
|
{
|
|
|
|
static const int DETAIL_LEFT = 5; ///< Number of pixels at the left
|
|
|
|
static const int DETAIL_RIGHT = 5; ///< Number of pixels at the right
|
|
|
|
static const int DETAIL_TOP = 5; ///< Number of pixels at the top
|
|
|
|
|
2009-11-15 18:39:22 +00:00
|
|
|
/* Height for the title banner */
|
|
|
|
int DETAIL_TITLE_HEIGHT = 5 * FONT_HEIGHT_NORMAL;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
/* Create the nice grayish rectangle at the details top */
|
2009-10-22 14:26:18 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + DETAIL_TITLE_HEIGHT, 157);
|
|
|
|
DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_INSET_TOP, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_CENTER);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-10-22 16:45:29 +00:00
|
|
|
/* Draw the total download size */
|
|
|
|
SetDParam(0, this->filesize_sum);
|
|
|
|
DrawString(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_NORMAL, STR_CONTENT_TOTAL_DOWNLOAD_SIZE);
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
if (this->selected == NULL) return;
|
|
|
|
|
|
|
|
/* And fill the rest of the details when there's information to place there */
|
2009-10-22 14:26:18 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + DETAIL_TITLE_HEIGHT / 2, r.top + DETAIL_TITLE_HEIGHT, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
/* Also show the total download size, so keep some space from the bottom */
|
2009-10-22 14:26:18 +00:00
|
|
|
const uint max_y = r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_WIDE;
|
|
|
|
int y = r.top + DETAIL_TITLE_HEIGHT + DETAIL_TOP;
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-01-20 21:05:13 +00:00
|
|
|
if (this->selected->upgrade) {
|
2009-01-17 16:53:32 +00:00
|
|
|
SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_UPDATE);
|
|
|
|
y += WD_PAR_VSEP_WIDE;
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetDParamStr(0, this->selected->name);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_NAME);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
if (!StrEmpty(this->selected->version)) {
|
|
|
|
SetDParamStr(0, this->selected->version);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_VERSION);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!StrEmpty(this->selected->description)) {
|
|
|
|
SetDParamStr(0, this->selected->description);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DESCRIPTION);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!StrEmpty(this->selected->url)) {
|
|
|
|
SetDParamStr(0, this->selected->url);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_URL);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TYPE);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-10-22 14:26:18 +00:00
|
|
|
y += WD_PAR_VSEP_WIDE;
|
2009-01-17 16:53:32 +00:00
|
|
|
SetDParam(0, this->selected->filesize);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_FILESIZE);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
if (this->selected->dependency_count != 0) {
|
|
|
|
/* List dependencies */
|
2009-10-22 14:26:18 +00:00
|
|
|
char buf[DRAW_STRING_BUFFER] = "";
|
2009-01-17 16:53:32 +00:00
|
|
|
char *p = buf;
|
|
|
|
for (uint i = 0; i < this->selected->dependency_count; i++) {
|
|
|
|
ContentID cid = this->selected->dependencies[i];
|
|
|
|
|
|
|
|
/* Try to find the dependency */
|
2009-01-20 16:51:55 +00:00
|
|
|
ConstContentIterator iter = _network_content_client.Begin();
|
|
|
|
for (; iter != _network_content_client.End(); iter++) {
|
2009-01-17 16:53:32 +00:00
|
|
|
const ContentInfo *ci = *iter;
|
|
|
|
if (ci->id != cid) continue;
|
|
|
|
|
|
|
|
p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", (*iter)->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetDParamStr(0, buf);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DEPENDENCIES);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->selected->tag_count != 0) {
|
|
|
|
/* List all tags */
|
2009-10-22 14:26:18 +00:00
|
|
|
char buf[DRAW_STRING_BUFFER] = "";
|
2009-01-17 16:53:32 +00:00
|
|
|
char *p = buf;
|
|
|
|
for (uint i = 0; i < this->selected->tag_count; i++) {
|
|
|
|
p += seprintf(p, lastof(buf), i == 0 ? "%s" : ", %s", this->selected->tags[i]);
|
|
|
|
}
|
|
|
|
SetDParamStr(0, buf);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TAGS);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->selected->IsSelected()) {
|
|
|
|
/* When selected show all manually selected content that depends on this */
|
2009-01-20 16:51:55 +00:00
|
|
|
ConstContentVector tree;
|
|
|
|
_network_content_client.ReverseLookupTreeDependency(tree, this->selected);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-10-22 14:26:18 +00:00
|
|
|
char buf[DRAW_STRING_BUFFER] = "";
|
2009-01-17 16:53:32 +00:00
|
|
|
char *p = buf;
|
2009-01-20 16:51:55 +00:00
|
|
|
for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) {
|
|
|
|
const ContentInfo *ci = *iter;
|
2009-01-17 16:53:32 +00:00
|
|
|
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
|
|
|
|
|
|
|
|
p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name);
|
|
|
|
}
|
|
|
|
if (p != buf) {
|
|
|
|
SetDParamStr(0, buf);
|
2009-10-22 14:26:18 +00:00
|
|
|
y = DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDoubleClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
/* Double clicking on a line in the matrix toggles the state of the checkbox */
|
|
|
|
if (widget != NCLWW_MATRIX) return;
|
|
|
|
|
2009-10-22 16:45:29 +00:00
|
|
|
pt.x = this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX)->pos_x;
|
2009-01-17 16:53:32 +00:00
|
|
|
this->OnClick(pt, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case NCLWW_MATRIX: {
|
2009-10-22 16:45:29 +00:00
|
|
|
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NCLWW_MATRIX)->pos_y) / this->resize.step_height;
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-09-02 08:08:30 +00:00
|
|
|
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
|
|
|
|
id_v += this->vscroll.GetPosition();
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
if (id_v >= this->content.Length()) return; // click out of bounds
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
this->selected = *this->content.Get(id_v);
|
2009-01-17 16:53:32 +00:00
|
|
|
this->list_pos = id_v;
|
|
|
|
|
2009-11-22 13:22:53 +00:00
|
|
|
if (pt.x <= (int)(this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX)->pos_y + this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX)->current_y)) {
|
2009-01-22 14:15:52 +00:00
|
|
|
_network_content_client.ToggleSelectedState(this->selected);
|
|
|
|
this->content.ForceResort();
|
|
|
|
}
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
} break;
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
case NCLWW_CHECKBOX:
|
|
|
|
case NCLWW_TYPE:
|
|
|
|
case NCLWW_NAME:
|
|
|
|
if (this->content.SortType() == widget - NCLWW_CHECKBOX) {
|
|
|
|
this->content.ToggleSortOrder();
|
|
|
|
this->list_pos = this->content.Length() - this->list_pos - 1;
|
|
|
|
} else {
|
|
|
|
this->content.SetSortType(widget - NCLWW_CHECKBOX);
|
|
|
|
this->content.ForceResort();
|
|
|
|
this->SortContentList();
|
|
|
|
}
|
|
|
|
this->ScrollToSelected();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-22 14:15:52 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
case NCLWW_SELECT_ALL:
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.SelectAll();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-20 16:51:55 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
case NCLWW_SELECT_UPDATE:
|
2009-01-20 21:05:13 +00:00
|
|
|
_network_content_client.SelectUpgrade();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_UNSELECT:
|
2009-01-23 02:01:05 +00:00
|
|
|
_network_content_client.UnselectAll();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_CANCEL:
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NCLWW_DOWNLOAD:
|
2009-03-19 17:56:45 +00:00
|
|
|
if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, 0) == NULL) new NetworkContentDownloadStatusWindow();
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
virtual void OnMouseLoop()
|
2009-01-17 16:53:32 +00:00
|
|
|
{
|
2009-02-06 12:00:14 +00:00
|
|
|
this->HandleEditBox(NCLWW_FILTER);
|
|
|
|
}
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
2009-01-17 16:53:32 +00:00
|
|
|
switch (keycode) {
|
|
|
|
case WKC_UP:
|
|
|
|
/* scroll up by one */
|
|
|
|
if (this->list_pos > 0) this->list_pos--;
|
|
|
|
break;
|
|
|
|
case WKC_DOWN:
|
|
|
|
/* scroll down by one */
|
2009-01-22 14:15:52 +00:00
|
|
|
if (this->list_pos < (int)this->content.Length() - 1) this->list_pos++;
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
case WKC_PAGEUP:
|
|
|
|
/* scroll up a page */
|
2009-09-02 08:08:30 +00:00
|
|
|
this->list_pos = (this->list_pos < this->vscroll.GetCapacity()) ? 0 : this->list_pos - this->vscroll.GetCapacity();
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
case WKC_PAGEDOWN:
|
|
|
|
/* scroll down a page */
|
2009-09-02 08:08:30 +00:00
|
|
|
this->list_pos = min(this->list_pos + this->vscroll.GetCapacity(), (int)this->content.Length() - 1);
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
case WKC_HOME:
|
|
|
|
/* jump to beginning */
|
|
|
|
this->list_pos = 0;
|
|
|
|
break;
|
|
|
|
case WKC_END:
|
|
|
|
/* jump to end */
|
2009-01-22 14:15:52 +00:00
|
|
|
this->list_pos = this->content.Length() - 1;
|
2009-01-17 16:53:32 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-24 13:32:18 +00:00
|
|
|
case WKC_SPACE:
|
2009-02-06 12:00:14 +00:00
|
|
|
case WKC_RETURN:
|
2009-02-24 13:32:18 +00:00
|
|
|
if (keycode == WKC_RETURN || !IsWidgetFocused(NCLWW_FILTER)) {
|
|
|
|
if (this->selected != NULL) {
|
|
|
|
_network_content_client.ToggleSelectedState(this->selected);
|
|
|
|
this->content.ForceResort();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-02-24 13:32:18 +00:00
|
|
|
}
|
|
|
|
return ES_HANDLED;
|
2009-01-23 18:40:18 +00:00
|
|
|
}
|
2009-02-24 13:32:18 +00:00
|
|
|
/* Fall through when pressing space is pressed and filter isn't focused */
|
2009-01-17 16:53:32 +00:00
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
default: {
|
|
|
|
/* Handle editbox input */
|
|
|
|
EventState state = ES_NOT_HANDLED;
|
|
|
|
if (this->HandleEditBoxKey(NCLWW_FILTER, key, keycode, state) == HEBR_EDITING) {
|
|
|
|
this->OnOSKInput(NCLWW_FILTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
if (_network_content_client.Length() == 0) return ES_HANDLED;
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
this->selected = *this->content.Get(this->list_pos);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
/* scroll to the new server if it is outside the current range */
|
|
|
|
this->ScrollToSelected();
|
|
|
|
|
|
|
|
/* redraw window */
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
return ES_HANDLED;
|
|
|
|
}
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
virtual void OnOSKInput(int wid)
|
|
|
|
{
|
|
|
|
this->content.SetFilterState(!StrEmpty(this->edit_str_buf));
|
|
|
|
this->content.ForceRebuild();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-02-06 12:00:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-01-17 16:53:32 +00:00
|
|
|
{
|
2009-10-22 16:45:29 +00:00
|
|
|
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(NCLWW_MATRIX)->current_y / this->resize.step_height);
|
|
|
|
this->GetWidget<NWidgetCore>(NCLWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 16:51:55 +00:00
|
|
|
virtual void OnReceiveContentInfo(const ContentInfo *rci)
|
2009-01-17 16:53:32 +00:00
|
|
|
{
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.ForceRebuild();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDownloadComplete(ContentID cid)
|
|
|
|
{
|
2009-01-22 14:15:52 +00:00
|
|
|
this->content.ForceResort();
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
2009-01-20 16:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnConnect(bool success)
|
|
|
|
{
|
|
|
|
if (!success) {
|
2009-10-31 19:46:51 +00:00
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, 0, 0);
|
2009-01-20 16:51:55 +00:00
|
|
|
delete this;
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
2009-01-20 16:51:55 +00:00
|
|
|
|
2009-10-22 13:57:39 +00:00
|
|
|
this->InvalidateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
|
|
|
/* To sum all the bytes we intend to download */
|
|
|
|
this->filesize_sum = 0;
|
|
|
|
bool show_select_all = false;
|
|
|
|
bool show_select_upgrade = false;
|
|
|
|
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
|
|
|
|
const ContentInfo *ci = *iter;
|
|
|
|
switch (ci->state) {
|
|
|
|
case ContentInfo::SELECTED:
|
|
|
|
case ContentInfo::AUTOSELECTED:
|
|
|
|
this->filesize_sum += ci->filesize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ContentInfo::UNSELECTED:
|
|
|
|
show_select_all = true;
|
|
|
|
show_select_upgrade |= ci->upgrade;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->SetWidgetDisabledState(NCLWW_DOWNLOAD, this->filesize_sum == 0 || FindWindowById(WC_NETWORK_STATUS_WINDOW, 0) != NULL);
|
|
|
|
this->SetWidgetDisabledState(NCLWW_UNSELECT, this->filesize_sum == 0);
|
|
|
|
this->SetWidgetDisabledState(NCLWW_SELECT_ALL, !show_select_all);
|
|
|
|
this->SetWidgetDisabledState(NCLWW_SELECT_UPDATE, !show_select_upgrade);
|
|
|
|
|
2009-10-22 16:45:29 +00:00
|
|
|
this->GetWidget<NWidgetCore>(NCLWW_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
Listing NetworkContentListWindow::last_sorting = {false, 1};
|
2009-02-06 12:00:14 +00:00
|
|
|
Filtering NetworkContentListWindow::last_filtering = {false, 0};
|
|
|
|
|
2009-01-22 14:15:52 +00:00
|
|
|
NetworkContentListWindow::GUIContentList::SortFunction * const NetworkContentListWindow::sorter_funcs[] = {
|
|
|
|
&StateSorter,
|
|
|
|
&TypeSorter,
|
|
|
|
&NameSorter,
|
|
|
|
};
|
|
|
|
|
2009-02-06 12:00:14 +00:00
|
|
|
NetworkContentListWindow::GUIContentList::FilterFunction * const NetworkContentListWindow::filter_funcs[] = {
|
|
|
|
&TagNameFilter,
|
|
|
|
};
|
|
|
|
|
2009-05-05 20:08:50 +00:00
|
|
|
static const NWidgetPart _nested_network_content_list_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, NCLWW_CLOSE),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, NCLWW_CAPTION), SetDataTip(STR_CONTENT_TITLE, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, NCLWW_BACKGROUND),
|
2009-10-22 16:45:29 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
|
|
|
|
/* Top */
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EMPTY, COLOUR_LIGHT_BLUE, NCLWW_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, NCLWW_FILTER), SetFill(1, 0), SetResize(1, 0),
|
2009-10-22 16:45:29 +00:00
|
|
|
SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
|
2009-05-05 20:08:50 +00:00
|
|
|
/* Left side. */
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-10-22 16:45:29 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_CHECKBOX), SetMinimalSize(13, 1), SetDataTip(STR_EMPTY, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_TYPE),
|
2009-08-05 17:59:21 +00:00
|
|
|
SetDataTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_NAME), SetResize(1, 0), SetFill(1, 0),
|
2009-08-05 17:59:21 +00:00
|
|
|
SetDataTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, NCLWW_MATRIX), SetResize(1, 14), SetFill(1, 1),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_LIGHT_BLUE, NCLWW_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
/* Right side. */
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, NCLWW_DETAILS), SetResize(1, 1), SetFill(1, 1), EndContainer(),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0),
|
|
|
|
/* Bottom. */
|
2009-10-22 16:45:29 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(8, 8, 8),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, NCLWW_SEL_ALL_UPDATE), SetResize(1, 0), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_SELECT_UPDATE), SetResize(1, 0), SetFill(1, 0),
|
2009-08-05 17:59:21 +00:00
|
|
|
SetDataTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_SELECT_ALL), SetResize(1, 0), SetFill(1, 0),
|
2009-10-22 16:45:29 +00:00
|
|
|
SetDataTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_UNSELECT), SetResize(1, 0), SetFill(1, 0),
|
2009-08-05 17:59:21 +00:00
|
|
|
SetDataTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_CANCEL), SetResize(1, 0), SetFill(1, 0),
|
2009-10-22 16:45:29 +00:00
|
|
|
SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, NCLWW_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
|
2009-08-05 17:59:21 +00:00
|
|
|
SetDataTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
|
2009-05-05 20:08:50 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 2), SetResize(1, 0),
|
|
|
|
/* Resize button. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
|
2009-05-05 20:08:50 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE, NCLWW_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
/** Window description of the content list */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _network_content_list_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 630, 460,
|
2009-01-17 16:53:32 +00:00
|
|
|
WC_NETWORK_WINDOW, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_network_content_list_widgets, lengthof(_nested_network_content_list_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the content list window with a given set of content
|
|
|
|
* @param cv the content to show, or NULL when it has to search for itself
|
|
|
|
* @param type the type to (only) show
|
|
|
|
*/
|
|
|
|
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type)
|
|
|
|
{
|
|
|
|
#if defined(WITH_ZLIB)
|
2009-01-23 10:20:29 +00:00
|
|
|
_network_content_client.Clear();
|
2009-01-20 16:51:55 +00:00
|
|
|
if (cv == NULL) {
|
2009-01-20 21:05:13 +00:00
|
|
|
_network_content_client.RequestContentList(type);
|
2009-01-17 16:53:32 +00:00
|
|
|
} else {
|
2009-01-20 16:51:55 +00:00
|
|
|
_network_content_client.RequestContentList(cv, true);
|
|
|
|
}
|
|
|
|
|
2009-03-19 17:56:45 +00:00
|
|
|
DeleteWindowById(WC_NETWORK_WINDOW, 1);
|
2009-01-20 16:51:55 +00:00
|
|
|
new NetworkContentListWindow(&_network_content_list_desc, cv != NULL);
|
2009-01-17 16:53:32 +00:00
|
|
|
#else
|
2009-10-31 19:46:51 +00:00
|
|
|
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, 0, 0);
|
2009-01-20 16:51:55 +00:00
|
|
|
/* Connection failed... clean up the mess */
|
|
|
|
if (cv != NULL) {
|
|
|
|
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) delete *iter;
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
2009-01-20 16:51:55 +00:00
|
|
|
#endif /* WITH_ZLIB */
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ENABLE_NETWORK */
|