update to 1.6.0

--HG--
branch : openttd
This commit is contained in:
Pavel Stupnikov
2016-04-02 00:50:09 +03:00
parent fe10aa3cba
commit 5c9ef5a264
223 changed files with 4115 additions and 3050 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: network.cpp 27431 2015-11-01 11:59:17Z frosch $ */
/* $Id: network.cpp 27400 2015-09-19 16:49:46Z rubidium $ */
/*
* This file is part of OpenTTD.

View File

@@ -1,4 +1,4 @@
/* $Id: network_content.h 23465 2011-12-09 21:49:52Z yexo $ */
/* $Id: network_content.h 27468 2015-12-10 18:28:01Z zuu $ */
/*
* This file is part of OpenTTD.
@@ -149,7 +149,7 @@ public:
extern ClientNetworkContentSocketHandler _network_content_client;
void ShowNetworkContentListWindow(ContentVector *cv = NULL, ContentType type = CONTENT_TYPE_END);
void ShowNetworkContentListWindow(ContentVector *cv = NULL, ContentType type1 = CONTENT_TYPE_END, ContentType type2 = CONTENT_TYPE_END);
void ShowMissingContentWindow(const struct GRFConfig *list);

View File

@@ -1,4 +1,4 @@
/* $Id: network_content_gui.cpp 26921 2014-09-25 19:27:07Z peter1138 $ */
/* $Id: network_content_gui.cpp 27469 2015-12-10 19:58:33Z zuu $ */
/*
* This file is part of OpenTTD.
@@ -29,6 +29,8 @@
#include "table/strings.h"
#include "../table/sprites.h"
#include <bitset>
#include "../safeguards.h"
@@ -282,10 +284,22 @@ public:
}
};
/** Filter data for NetworkContentListWindow. */
struct ContentListFilterData {
StringFilter string_filter; ///< Text filter of content list
std::bitset<CONTENT_TYPE_END> types; ///< Content types displayed
};
/** Filter criterias 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
};
/** Window that lists the content that's at the content server */
class NetworkContentListWindow : public Window, ContentCallback {
/** List with content infos. */
typedef GUIList<const ContentInfo *, StringFilter &> GUIContentList;
typedef GUIList<const ContentInfo *, ContentListFilterData &> GUIContentList;
static const uint EDITBOX_MAX_SIZE = 50; ///< Maximum size of the editbox in characters.
@@ -295,7 +309,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
static GUIContentList::FilterFunction * const filter_funcs[]; ///< Filter functions.
GUIContentList content; ///< List with content
bool auto_select; ///< Automatically select all content when the meta-data becomes available
StringFilter string_filter; ///< Filter for content list
ContentListFilterData filter_data; ///< Filter for content list
QueryString filter_editbox; ///< Filter editbox;
Dimension checkbox_size; ///< Size of checkbox/"blot" sprite
@@ -304,6 +318,8 @@ class NetworkContentListWindow : public Window, ContentCallback {
uint filesize_sum; ///< The sum of all selected file sizes
Scrollbar *vscroll; ///< Cache of the vertical scrollbar
static char content_type_strs[CONTENT_TYPE_END][64]; ///< Cached strings for all content types.
/** Search external websites for content */
void OpenExternalSearch()
{
@@ -401,11 +417,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
{
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 = strnatcmp(a_str, b_str);
r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]);
}
if (r == 0) r = NameSorter(a, b);
return r;
@@ -433,20 +445,38 @@ class NetworkContentListWindow : public Window, ContentCallback {
}
/** Filter content by tags/name */
static bool CDECL TagNameFilter(const ContentInfo * const *a, StringFilter &filter)
static bool CDECL TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
{
filter.ResetState();
filter.string_filter.ResetState();
for (int i = 0; i < (*a)->tag_count; i++) {
filter.AddLine((*a)->tags[i]);
filter.string_filter.AddLine((*a)->tags[i]);
}
filter.AddLine((*a)->name);
return filter.GetState();
filter.string_filter.AddLine((*a)->name);
return filter.string_filter.GetState();
}
/** Filter content by type, but still show content selected for download. */
static bool CDECL TypeOrSelectedFilter(const ContentInfo * const *a, ContentListFilterData &filter)
{
if (filter.types.none()) return true;
if (filter.types[(*a)->type]) return true;
return ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED);
}
/** Filter the content list */
void FilterContentList()
{
if (!this->content.Filter(this->string_filter)) return;
/* Apply filters. */
bool changed = false;
if (!this->filter_data.string_filter.IsEmpty()) {
this->content.SetFilterType(CONTENT_FILTER_TEXT);
changed |= this->content.Filter(this->filter_data);
}
if (this->filter_data.types.any()) {
this->content.SetFilterType(CONTENT_FILTER_TYPE_OR_SELECTED);
changed |= this->content.Filter(this->filter_data);
}
if (!changed) return;
/* update list position */
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
@@ -461,6 +491,20 @@ class NetworkContentListWindow : public Window, ContentCallback {
this->list_pos = 0;
}
/**
* Update filter state based on current window state.
* @return true if filter state was changed, otherwise false.
*/
bool UpdateFilterState()
{
Filtering old_params = this->content.GetFiltering();
bool new_state = !this->filter_data.string_filter.IsEmpty() || this->filter_data.types.any();
if (new_state != old_params.state) {
this->content.SetFilterState(new_state);
}
return new_state != old_params.state;
}
/** Make sure that the currently selected content info is within the visible part of the matrix */
void ScrollToSelected()
{
@@ -469,13 +513,18 @@ class NetworkContentListWindow : public Window, ContentCallback {
this->vscroll->ScrollTowards(this->list_pos);
}
friend void BuildContentTypeStringList();
public:
/**
* Create the content list window.
* @param desc the window description to pass to Window's constructor.
* @param select_all Whether the select all button is allowed or not.
* @param type the main type of content to display or #CONTENT_TYPE_END.
* When a type other than #CONTENT_TYPE_END is given, dependencies of
* other types are only shown when content that depend on them are
* selected.
*/
NetworkContentListWindow(WindowDesc *desc, bool select_all) :
NetworkContentListWindow(WindowDesc *desc, bool select_all, const std::bitset<CONTENT_TYPE_END> &types) :
Window(desc),
auto_select(select_all),
filter_editbox(EDITBOX_MAX_SIZE),
@@ -494,12 +543,14 @@ public:
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
this->SetFocusedWidget(WID_NCL_FILTER);
this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
this->filter_data.types = types;
_network_content_client.AddCallback(this);
this->content.SetListing(this->last_sorting);
this->content.SetFiltering(this->last_filtering);
this->content.SetSortFuncs(this->sorter_funcs);
this->content.SetFilterFuncs(this->filter_funcs);
this->UpdateFilterState();
this->content.ForceRebuild();
this->FilterContentList();
this->SortContentList();
@@ -752,6 +803,10 @@ public:
this->content.ForceResort();
}
if (this->filter_data.types.any()) {
this->content.ForceRebuild();
}
this->InvalidateData();
break;
}
@@ -847,9 +902,13 @@ public:
this->content.ForceResort();
this->InvalidateData();
}
if (this->filter_data.types.any()) {
this->content.ForceRebuild();
this->InvalidateData();
}
return ES_HANDLED;
}
/* FALL THROUGH, space is pressed and filter isn't focused. */
/* FALL THROUGH, space is pressed and filter is focused. */
default:
return ES_NOT_HANDLED;
@@ -857,13 +916,21 @@ public:
if (this->content.Length() == 0) {
this->list_pos = 0; // above stuff may result in "-1".
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
this->InvalidateData();
}
return ES_HANDLED;
}
this->selected = *this->content.Get(this->list_pos);
/* scroll to the new server if it is outside the current range */
this->ScrollToSelected();
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
} else {
/* Scroll to the new content if it is outside the current range. */
this->ScrollToSelected();
}
/* redraw window */
this->InvalidateData();
@@ -873,8 +940,8 @@ public:
virtual void OnEditboxChanged(int wid)
{
if (wid == WID_NCL_FILTER) {
this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
this->content.SetFilterState(!this->string_filter.IsEmpty());
this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.buf);
this->UpdateFilterState();
this->content.ForceRebuild();
this->InvalidateData();
}
@@ -966,8 +1033,21 @@ NetworkContentListWindow::GUIContentList::SortFunction * const NetworkContentLis
NetworkContentListWindow::GUIContentList::FilterFunction * const NetworkContentListWindow::filter_funcs[] = {
&TagNameFilter,
&TypeOrSelectedFilter,
};
char NetworkContentListWindow::content_type_strs[CONTENT_TYPE_END][64];
/**
* Build array of all strings corresponding to the content types.
*/
void BuildContentTypeStringList()
{
for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
GetString(NetworkContentListWindow::content_type_strs[i], STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS, lastof(NetworkContentListWindow::content_type_strs[i]));
}
}
/** The widgets for the content list. */
static const NWidgetPart _nested_network_content_list_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -1056,20 +1136,29 @@ 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 type the type to (only) show
* @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.
*/
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type)
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentType type2)
{
#if defined(WITH_ZLIB)
std::bitset<CONTENT_TYPE_END> types;
_network_content_client.Clear();
if (cv == NULL) {
_network_content_client.RequestContentList(type);
assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
assert(type1 == CONTENT_TYPE_END || type1 != type2);
_network_content_client.RequestContentList(type1);
if (type2 != CONTENT_TYPE_END) _network_content_client.RequestContentList(type2);
if (type1 != CONTENT_TYPE_END) types[type1] = true;
if (type2 != CONTENT_TYPE_END) types[type2] = true;
} else {
_network_content_client.RequestContentList(cv, true);
}
DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
new NetworkContentListWindow(&_network_content_list_desc, cv != NULL);
new NetworkContentListWindow(&_network_content_list_desc, cv != NULL, types);
#else
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
/* Connection failed... clean up the mess */

View File

@@ -1,4 +1,4 @@
/* $Id: network_content_gui.h 25287 2013-05-26 19:23:42Z frosch $ */
/* $Id: network_content_gui.h 27288 2015-05-17 19:49:35Z michi_cc $ */
/*
* This file is part of OpenTTD.
@@ -43,4 +43,6 @@ public:
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes);
};
void BuildContentTypeStringList();
#endif /* NETWORK_CONTENT_GUI_H */

View File

@@ -1,4 +1,4 @@
/* $Id: network_func.h 27431 2015-11-01 11:59:17Z frosch $ */
/* $Id: network_func.h 27400 2015-09-19 16:49:46Z rubidium $ */
/*
* This file is part of OpenTTD.

View File

@@ -1,4 +1,4 @@
/* $Id: network_gui.cpp 27431 2015-11-01 11:59:17Z frosch $ */
/* $Id: network_gui.cpp 27421 2015-10-30 16:19:33Z frosch $ */
/*
* This file is part of OpenTTD.

View File

@@ -1,4 +1,4 @@
/* $Id: network_udp.cpp 27431 2015-11-01 11:59:17Z frosch $ */
/* $Id: network_udp.cpp 27400 2015-09-19 16:49:46Z rubidium $ */
/*
* This file is part of OpenTTD.