Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -9,7 +9,6 @@
/** @file network_content_gui.cpp Implementation of the Network Content related GUIs. */
#if defined(ENABLE_NETWORK)
#include "../stdafx.h"
#include "../strings_func.h"
#include "../gfx_func.h"
@@ -65,7 +64,7 @@ struct ContentTextfileWindow : public TextfileWindow {
}
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, this->GetTypeString());
@@ -96,7 +95,7 @@ static const NWidgetPart _nested_network_content_download_status_window_widgets[
/** Window description for the download window */
static WindowDesc _network_content_download_status_window_desc(
WDP_CENTER, NULL, 0, 0,
WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_STATUS_WINDOW, WC_NONE,
WDF_MODAL,
_nested_network_content_download_status_window_widgets, lengthof(_nested_network_content_download_status_window_widgets)
@@ -116,7 +115,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
_network_content_client.RemoveCallback(this);
}
/* virtual */ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
{
if (widget != WID_NCDS_BACKGROUND) return;
@@ -145,7 +144,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
DrawStringMultiLine(r.left + 2, r.right - 2, y, y + FONT_HEIGHT_NORMAL * 2, str, TC_FROMSTRING, SA_CENTER);
}
/* virtual */ void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
{
if (ci->id != this->cur_id) {
strecpy(this->name, ci->filename, lastof(this->name));
@@ -161,7 +160,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
/** Window for showing the download status of content */
struct NetworkContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
private:
SmallVector<ContentType, 4> receivedTypes; ///< Types we received so we can update their cache
std::vector<ContentType> receivedTypes; ///< Types we received so we can update their cache
public:
/**
@@ -177,8 +176,8 @@ public:
~NetworkContentDownloadStatusWindow()
{
TarScanner::Mode mode = TarScanner::NONE;
for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
switch (*iter) {
for (auto ctype : this->receivedTypes) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
/* AI::Rescan calls the scanner. */
@@ -211,8 +210,8 @@ public:
TarScanner::DoScan(mode);
/* Tell all the backends about what we've downloaded */
for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
switch (*iter) {
for (auto ctype : this->receivedTypes) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
AI::Rescan();
@@ -239,7 +238,7 @@ public:
break;
case CONTENT_TYPE_NEWGRF:
ScanNewGRFFiles(NULL);
ScanNewGRFFiles(nullptr);
break;
case CONTENT_TYPE_SCENARIO:
@@ -258,7 +257,7 @@ public:
InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST, 2);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget == WID_NCDS_CANCELOK) {
if (this->downloaded_bytes != this->total_bytes) {
@@ -272,10 +271,10 @@ public:
}
}
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
{
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
this->receivedTypes.Include(ci->type);
include(this->receivedTypes, ci->type);
/* When downloading is finished change cancel in ok */
if (this->downloaded_bytes == this->total_bytes) {
@@ -290,7 +289,7 @@ struct ContentListFilterData {
std::bitset<CONTENT_TYPE_END> types; ///< Content types displayed
};
/** Filter criterias for NetworkContentListWindow. */
/** Filter criteria for NetworkContentListWindow. */
enum ContentListFilterCriteria {
CONTENT_FILTER_TEXT = 0, ///< Filter by query sting
CONTENT_FILTER_TYPE_OR_SELECTED,///< Filter by being of displayed type or selected for download
@@ -334,8 +333,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
pos = strecpy(pos, "do=searchgrfid&q=", last);
bool first = true;
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : this->content) {
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
if (!first) pos = strecpy(pos, ",", last);
@@ -386,49 +384,49 @@ class NetworkContentListWindow : public Window, ContentCallback {
if (!this->content.NeedRebuild()) return;
/* Create temporary array of games to use for listing */
this->content.Clear();
this->content.clear();
bool all_available = true;
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false;
*this->content.Append() = *iter;
this->content.push_back(*iter);
}
this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
this->FilterContentList();
this->content.Compact();
this->content.shrink_to_fit();
this->content.RebuildDone();
this->SortContentList();
this->vscroll->SetCount(this->content.Length()); // Update the scrollbar
this->vscroll->SetCount((int)this->content.size()); // Update the scrollbar
this->ScrollToSelected();
}
/** Sort content by name. */
static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
{
return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting).
return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting).
}
/** Sort content by type. */
static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b)
static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
{
int r = 0;
if ((*a)->type != (*b)->type) {
r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]);
if (a->type != b->type) {
r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]);
}
if (r == 0) r = NameSorter(a, b);
return r;
if (r == 0) return NameSorter(a, b);
return r < 0;
}
/** Sort content by state. */
static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b)
static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
{
int r = (*a)->state - (*b)->state;
if (r == 0) r = TypeSorter(a, b);
return r;
int r = a->state - b->state;
if (r == 0) return TypeSorter(a, b);
return r < 0;
}
/** Sort the content list */
@@ -436,12 +434,8 @@ class NetworkContentListWindow : public Window, ContentCallback {
{
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;
}
}
int idx = find_index(this->content, this->selected);
if (idx >= 0) this->list_pos = idx;
}
/** Filter content by tags/name */
@@ -479,15 +473,14 @@ class NetworkContentListWindow : public Window, ContentCallback {
if (!changed) return;
/* update list position */
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
if (*iter == this->selected) {
this->list_pos = iter - this->content.Begin();
return;
}
int idx = find_index(this->content, this->selected);
if (idx >= 0) {
this->list_pos = idx;
return;
}
/* previously selected item not in list anymore */
this->selected = NULL;
this->selected = nullptr;
this->list_pos = 0;
}
@@ -508,7 +501,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
/** Make sure that the currently selected content info is within the visible part of the matrix */
void ScrollToSelected()
{
if (this->selected == NULL) return;
if (this->selected == nullptr) return;
this->vscroll->ScrollTowards(this->list_pos);
}
@@ -528,7 +521,7 @@ public:
Window(desc),
auto_select(select_all),
filter_editbox(EDITBOX_MAX_SIZE),
selected(NULL),
selected(nullptr),
list_pos(0)
{
this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT));
@@ -563,7 +556,7 @@ public:
_network_content_client.RemoveCallback(this);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
@@ -591,7 +584,7 @@ public:
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
@@ -608,7 +601,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
@@ -641,8 +634,12 @@ public:
int sprite_y_offset = WD_MATRIX_TOP + (line_height - this->checkbox_size.height) / 2 - 1;
int text_y_offset = WD_MATRIX_TOP + (line_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top;
int cnt = 0;
for (ConstContentIterator iter = this->content.Get(this->vscroll->GetPosition()); iter != this->content.End() && cnt < this->vscroll->GetCapacity(); iter++, cnt++) {
auto iter = this->content.begin() + this->vscroll->GetPosition();
size_t last = this->vscroll->GetPosition() + this->vscroll->GetCapacity();
auto end = (last < this->content.size()) ? this->content.begin() + last : this->content.end();
for (/**/; iter != end; iter++) {
const ContentInfo *ci = *iter;
if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, PC_GREY);
@@ -688,7 +685,7 @@ public:
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);
if (this->selected == NULL) return;
if (this->selected == nullptr) return;
/* And fill the rest of the details when there's information to place there */
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);
@@ -767,8 +764,7 @@ public:
char buf[DRAW_STRING_BUFFER] = "";
char *p = buf;
for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : tree) {
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name);
@@ -780,10 +776,10 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_END) {
if (this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE) return;
if (this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE) return;
ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
return;
@@ -792,9 +788,9 @@ public:
switch (widget) {
case WID_NCL_MATRIX: {
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX);
if (id_v >= this->content.Length()) return; // click out of bounds
if (id_v >= this->content.size()) return; // click out of bounds
this->selected = *this->content.Get(id_v);
this->selected = this->content[id_v];
this->list_pos = id_v;
const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
@@ -816,7 +812,7 @@ public:
case WID_NCL_NAME:
if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
this->content.ToggleSortOrder();
if (this->content.Length() > 0) this->list_pos = this->content.Length() - this->list_pos - 1;
if (this->content.size() > 0) this->list_pos = (int)this->content.size() - this->list_pos - 1;
} else {
this->content.SetSortType(widget - WID_NCL_CHECKBOX);
this->content.ForceResort();
@@ -846,14 +842,14 @@ public:
break;
case WID_NCL_OPEN_URL:
if (this->selected != NULL) {
if (this->selected != nullptr) {
extern void OpenBrowser(const char *url);
OpenBrowser(this->selected->url);
}
break;
case WID_NCL_DOWNLOAD:
if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == NULL) new NetworkContentDownloadStatusWindow();
if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == nullptr) new NetworkContentDownloadStatusWindow();
break;
case WID_NCL_SEARCH_EXTERNAL:
@@ -866,7 +862,7 @@ public:
}
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
switch (keycode) {
case WKC_UP:
@@ -875,7 +871,7 @@ public:
break;
case WKC_DOWN:
/* scroll down by one */
if (this->list_pos < (int)this->content.Length() - 1) this->list_pos++;
if (this->list_pos < (int)this->content.size() - 1) this->list_pos++;
break;
case WKC_PAGEUP:
/* scroll up a page */
@@ -883,7 +879,7 @@ public:
break;
case WKC_PAGEDOWN:
/* scroll down a page */
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.Length() - 1);
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
@@ -891,13 +887,13 @@ public:
break;
case WKC_END:
/* jump to end */
this->list_pos = this->content.Length() - 1;
this->list_pos = (int)this->content.size() - 1;
break;
case WKC_SPACE:
case WKC_RETURN:
if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
if (this->selected != NULL) {
if (this->selected != nullptr) {
_network_content_client.ToggleSelectedState(this->selected);
this->content.ForceResort();
this->InvalidateData();
@@ -915,7 +911,7 @@ public:
return ES_NOT_HANDLED;
}
if (this->content.Length() == 0) {
if (this->content.size() == 0) {
this->list_pos = 0; // above stuff may result in "-1".
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
@@ -924,7 +920,7 @@ public:
return ES_HANDLED;
}
this->selected = *this->content.Get(this->list_pos);
this->selected = this->content[this->list_pos];
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
@@ -938,7 +934,7 @@ public:
return ES_HANDLED;
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_NCL_FILTER) {
this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.buf);
@@ -948,25 +944,25 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
}
virtual void OnReceiveContentInfo(const ContentInfo *rci)
void OnReceiveContentInfo(const ContentInfo *rci) override
{
if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci);
this->content.ForceRebuild();
this->InvalidateData();
}
virtual void OnDownloadComplete(ContentID cid)
void OnDownloadComplete(ContentID cid) override
{
this->content.ForceResort();
this->InvalidateData();
}
virtual void OnConnect(bool success)
void OnConnect(bool success) override
{
if (!success) {
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
@@ -982,7 +978,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
if (this->content.NeedRebuild()) this->BuildContentList();
@@ -991,8 +987,7 @@ public:
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;
for (const ContentInfo *ci : this->content) {
switch (ci->state) {
case ContentInfo::SELECTED:
case ContentInfo::AUTOSELECTED:
@@ -1010,13 +1005,13 @@ public:
}
/* If data == 2 then the status window caused this OnInvalidate */
this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != NULL && data != 2));
this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != nullptr && data != 2));
this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == NULL || StrEmpty(this->selected->url));
this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || StrEmpty(this->selected->url));
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == NULL);
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == nullptr);
}
this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
@@ -1136,7 +1131,7 @@ static WindowDesc _network_content_list_desc(
/**
* 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 cv the content to show, or nullptr when it has to search for itself
* @param type1 the first type to (only) show or #CONTENT_TYPE_END to show all.
* @param type2 the second type to (only) show in addition to type1. If type2 is != #CONTENT_TYPE_END, then also type1 should be != #CONTENT_TYPE_END.
* If type2 != #CONTENT_TYPE_END, then type1 != type2 must be true.
@@ -1146,7 +1141,7 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
#if defined(WITH_ZLIB)
std::bitset<CONTENT_TYPE_END> types;
_network_content_client.Clear();
if (cv == NULL) {
if (cv == nullptr) {
assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
assert(type1 == CONTENT_TYPE_END || type1 != type2);
_network_content_client.RequestContentList(type1);
@@ -1159,14 +1154,12 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
}
DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
new NetworkContentListWindow(&_network_content_list_desc, cv != NULL, types);
new NetworkContentListWindow(&_network_content_list_desc, cv != nullptr, types);
#else
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
/* Connection failed... clean up the mess */
if (cv != NULL) {
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) delete *iter;
if (cv != nullptr) {
for (ContentInfo *ci : *cv) delete ci;
}
#endif /* WITH_ZLIB */
}
#endif /* ENABLE_NETWORK */