2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
8 /** @file network_content_gui.cpp Implementation of the Network Content related GUIs. */
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../gfx_func.h"
13 #include "../window_func.h"
15 #include "../ai/ai.hpp"
16 #include "../game/game.hpp"
17 #include "../base_media_base.h"
18 #include "../openttd.h"
19 #include "../sortlist_type.h"
20 #include "../stringfilter_type.h"
21 #include "../querystring_gui.h"
22 #include "../core/geometry_func.hpp"
23 #include "../textfile_gui.h"
25 #include "network_content_gui.h"
28 #include "table/strings.h"
29 #include "../table/sprites.h"
33 #include "../safeguards.h"
36 /** Whether the user accepted to enter external websites during this session. */
37 static bool _accepted_external_search
= false;
40 /** Window for displaying the textfile of an item in the content list. */
41 struct ContentTextfileWindow
: public TextfileWindow
{
42 const ContentInfo
*ci
; ///< View the textfile of this ContentInfo.
44 ContentTextfileWindow(TextfileType file_type
, const ContentInfo
*ci
) : TextfileWindow(file_type
), ci(ci
)
46 this->ConstructWindow();
48 auto textfile
= this->ci
->GetTextfile(file_type
);
49 this->LoadTextfile(textfile
.value(), GetContentInfoSubDir(this->ci
->type
));
52 StringID
GetTypeString() const
54 switch (this->ci
->type
) {
55 case CONTENT_TYPE_NEWGRF
: return STR_CONTENT_TYPE_NEWGRF
;
56 case CONTENT_TYPE_BASE_GRAPHICS
: return STR_CONTENT_TYPE_BASE_GRAPHICS
;
57 case CONTENT_TYPE_BASE_SOUNDS
: return STR_CONTENT_TYPE_BASE_SOUNDS
;
58 case CONTENT_TYPE_BASE_MUSIC
: return STR_CONTENT_TYPE_BASE_MUSIC
;
59 case CONTENT_TYPE_AI
: return STR_CONTENT_TYPE_AI
;
60 case CONTENT_TYPE_AI_LIBRARY
: return STR_CONTENT_TYPE_AI_LIBRARY
;
61 case CONTENT_TYPE_GAME
: return STR_CONTENT_TYPE_GAME_SCRIPT
;
62 case CONTENT_TYPE_GAME_LIBRARY
: return STR_CONTENT_TYPE_GS_LIBRARY
;
63 case CONTENT_TYPE_SCENARIO
: return STR_CONTENT_TYPE_SCENARIO
;
64 case CONTENT_TYPE_HEIGHTMAP
: return STR_CONTENT_TYPE_HEIGHTMAP
;
65 default: NOT_REACHED();
69 void SetStringParameters(WidgetID widget
) const override
71 if (widget
== WID_TF_CAPTION
) {
72 SetDParam(0, this->GetTypeString());
73 SetDParamStr(1, this->ci
->name
);
78 void ShowContentTextfileWindow(TextfileType file_type
, const ContentInfo
*ci
)
80 CloseWindowById(WC_TEXTFILE
, file_type
);
81 new ContentTextfileWindow(file_type
, ci
);
84 /** Nested widgets for the download window. */
85 static constexpr NWidgetPart _nested_network_content_download_status_window_widgets
[] = {
86 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
87 NWidget(WWT_PANEL
, COLOUR_GREY
),
88 NWidget(NWID_VERTICAL
), SetPIP(0, WidgetDimensions::unscaled
.vsep_wide
, 0), SetPadding(WidgetDimensions::unscaled
.modalpopup
),
89 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_NCDS_PROGRESS_BAR
), SetFill(1, 0),
90 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_NCDS_PROGRESS_TEXT
), SetFill(1, 0), SetMinimalSize(350, 0),
91 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCDS_CANCELOK
), SetDataTip(STR_BUTTON_CANCEL
, STR_NULL
), SetFill(1, 0),
96 /** Window description for the download window */
97 static WindowDesc
_network_content_download_status_window_desc(__FILE__
, __LINE__
,
98 WDP_CENTER
, nullptr, 0, 0,
99 WC_NETWORK_STATUS_WINDOW
, WC_NONE
,
101 std::begin(_nested_network_content_download_status_window_widgets
), std::end(_nested_network_content_download_status_window_widgets
)
104 BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(WindowDesc
*desc
) :
105 Window(desc
), downloaded_bytes(0), downloaded_files(0), cur_id(UINT32_MAX
)
107 _network_content_client
.AddCallback(this);
108 _network_content_client
.DownloadSelectedContent(this->total_files
, this->total_bytes
);
110 this->InitNested(WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
);
113 void BaseNetworkContentDownloadStatusWindow::Close([[maybe_unused
]] int data
)
115 _network_content_client
.RemoveCallback(this);
116 this->Window::Close();
119 void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget
, Dimension
*size
, [[maybe_unused
]] const Dimension
&padding
, [[maybe_unused
]] Dimension
*fill
, [[maybe_unused
]] Dimension
*resize
)
122 case WID_NCDS_PROGRESS_BAR
:
123 SetDParamMaxDigits(0, 8);
124 SetDParamMaxDigits(1, 8);
125 SetDParamMaxDigits(2, 8);
126 *size
= GetStringBoundingBox(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE
);
127 /* We need some spacing for the 'border' */
128 size
->height
+= WidgetDimensions::scaled
.frametext
.Horizontal();
129 size
->width
+= WidgetDimensions::scaled
.frametext
.Vertical();
132 case WID_NCDS_PROGRESS_TEXT
:
133 size
->height
= GetCharacterHeight(FS_NORMAL
) * 2 + WidgetDimensions::scaled
.vsep_normal
;
138 void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect
&r
, WidgetID widget
) const
141 case WID_NCDS_PROGRESS_BAR
: {
142 /* Draw the % complete with a bar and a text */
143 DrawFrameRect(r
, COLOUR_GREY
, FR_BORDERONLY
| FR_LOWERED
);
144 Rect ir
= r
.Shrink(WidgetDimensions::scaled
.bevel
);
145 DrawFrameRect(ir
.WithWidth((uint64_t)ir
.Width() * this->downloaded_bytes
/ this->total_bytes
, false), COLOUR_MAUVE
, FR_NONE
);
146 SetDParam(0, this->downloaded_bytes
);
147 SetDParam(1, this->total_bytes
);
148 SetDParam(2, this->downloaded_bytes
* 100LL / this->total_bytes
);
149 DrawString(ir
.left
, ir
.right
, CenterBounds(ir
.top
, ir
.bottom
, GetCharacterHeight(FS_NORMAL
)), STR_CONTENT_DOWNLOAD_PROGRESS_SIZE
, TC_FROMSTRING
, SA_HOR_CENTER
);
153 case WID_NCDS_PROGRESS_TEXT
: {
155 if (this->downloaded_bytes
== this->total_bytes
) {
156 str
= STR_CONTENT_DOWNLOAD_COMPLETE
;
157 } else if (!this->name
.empty()) {
158 SetDParamStr(0, this->name
);
159 SetDParam(1, this->downloaded_files
);
160 SetDParam(2, this->total_files
);
161 str
= STR_CONTENT_DOWNLOAD_FILE
;
163 str
= STR_CONTENT_DOWNLOAD_INITIALISE
;
165 DrawStringMultiLine(r
, str
, TC_FROMSTRING
, SA_CENTER
);
171 void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo
*ci
, int bytes
)
173 if (ci
->id
!= this->cur_id
) {
174 this->name
= ci
->filename
;
175 this->cur_id
= ci
->id
;
176 this->downloaded_files
++;
179 /* A negative value means we are resetting; for example, when retrying or using a fallback. */
181 this->downloaded_bytes
= 0;
183 this->downloaded_bytes
+= bytes
;
190 /** Window for showing the download status of content */
191 struct NetworkContentDownloadStatusWindow
: public BaseNetworkContentDownloadStatusWindow
{
193 std::vector
<ContentType
> receivedTypes
; ///< Types we received so we can update their cache
197 * Create a new download window based on a list of content information
198 * with flags whether to download them or not.
200 NetworkContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_network_content_download_status_window_desc
)
202 this->parent
= FindWindowById(WC_NETWORK_WINDOW
, WN_NETWORK_WINDOW_CONTENT_LIST
);
205 void Close([[maybe_unused
]] int data
= 0) override
207 TarScanner::Mode mode
= TarScanner::NONE
;
208 for (auto ctype
: this->receivedTypes
) {
210 case CONTENT_TYPE_AI
:
211 case CONTENT_TYPE_AI_LIBRARY
:
212 /* AI::Rescan calls the scanner. */
214 case CONTENT_TYPE_GAME
:
215 case CONTENT_TYPE_GAME_LIBRARY
:
216 /* Game::Rescan calls the scanner. */
219 case CONTENT_TYPE_BASE_GRAPHICS
:
220 case CONTENT_TYPE_BASE_SOUNDS
:
221 case CONTENT_TYPE_BASE_MUSIC
:
222 mode
|= TarScanner::BASESET
;
225 case CONTENT_TYPE_NEWGRF
:
226 /* ScanNewGRFFiles calls the scanner. */
229 case CONTENT_TYPE_SCENARIO
:
230 case CONTENT_TYPE_HEIGHTMAP
:
231 mode
|= TarScanner::SCENARIO
;
239 TarScanner::DoScan(mode
);
241 /* Tell all the backends about what we've downloaded */
242 for (auto ctype
: this->receivedTypes
) {
244 case CONTENT_TYPE_AI
:
245 case CONTENT_TYPE_AI_LIBRARY
:
249 case CONTENT_TYPE_GAME
:
250 case CONTENT_TYPE_GAME_LIBRARY
:
254 case CONTENT_TYPE_BASE_GRAPHICS
:
255 BaseGraphics::FindSets();
256 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_OPTIONS
);
259 case CONTENT_TYPE_BASE_SOUNDS
:
260 BaseSounds::FindSets();
261 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_OPTIONS
);
264 case CONTENT_TYPE_BASE_MUSIC
:
265 BaseMusic::FindSets();
266 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_OPTIONS
);
269 case CONTENT_TYPE_NEWGRF
:
273 case CONTENT_TYPE_SCENARIO
:
274 case CONTENT_TYPE_HEIGHTMAP
:
276 InvalidateWindowData(WC_SAVELOAD
, 0, 0);
284 /* Always invalidate the download window; tell it we are going to be gone */
285 InvalidateWindowData(WC_NETWORK_WINDOW
, WN_NETWORK_WINDOW_CONTENT_LIST
, 2);
287 this->BaseNetworkContentDownloadStatusWindow::Close();
290 void OnClick([[maybe_unused
]] Point pt
, WidgetID widget
, [[maybe_unused
]] int click_count
) override
292 if (widget
== WID_NCDS_CANCELOK
) {
293 if (this->downloaded_bytes
!= this->total_bytes
) {
294 _network_content_client
.Cancel();
297 /* If downloading succeeded, close the online content window. This will close
298 * the current window as well. */
299 CloseWindowById(WC_NETWORK_WINDOW
, WN_NETWORK_WINDOW_CONTENT_LIST
);
304 void OnDownloadProgress(const ContentInfo
*ci
, int bytes
) override
306 BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci
, bytes
);
307 include(this->receivedTypes
, ci
->type
);
309 /* When downloading is finished change cancel in ok */
310 if (this->downloaded_bytes
== this->total_bytes
) {
311 this->GetWidget
<NWidgetCore
>(WID_NCDS_CANCELOK
)->widget_data
= STR_BUTTON_OK
;
316 /** Filter data for NetworkContentListWindow. */
317 struct ContentListFilterData
{
318 StringFilter string_filter
; ///< Text filter of content list
319 std::bitset
<CONTENT_TYPE_END
> types
; ///< Content types displayed
322 /** Filter criteria for NetworkContentListWindow. */
323 enum ContentListFilterCriteria
{
324 CONTENT_FILTER_TEXT
= 0, ///< Filter by query sting
325 CONTENT_FILTER_TYPE_OR_SELECTED
,///< Filter by being of displayed type or selected for download
328 /** Window that lists the content that's at the content server */
329 class NetworkContentListWindow
: public Window
, ContentCallback
{
330 /** List with content infos. */
331 typedef GUIList
<const ContentInfo
*, std::nullptr_t
, ContentListFilterData
&> GUIContentList
;
333 static const uint EDITBOX_MAX_SIZE
= 50; ///< Maximum size of the editbox in characters.
335 static Listing last_sorting
; ///< The last sorting setting.
336 static Filtering last_filtering
; ///< The last filtering setting.
337 static GUIContentList::SortFunction
* const sorter_funcs
[]; ///< Sorter functions
338 static GUIContentList::FilterFunction
* const filter_funcs
[]; ///< Filter functions.
339 GUIContentList content
; ///< List with content
340 bool auto_select
; ///< Automatically select all content when the meta-data becomes available
341 ContentListFilterData filter_data
; ///< Filter for content list
342 QueryString filter_editbox
; ///< Filter editbox;
343 Dimension checkbox_size
; ///< Size of checkbox/"blot" sprite
345 const ContentInfo
*selected
; ///< The selected content info
346 int list_pos
; ///< Our position in the list
347 uint filesize_sum
; ///< The sum of all selected file sizes
348 Scrollbar
*vscroll
; ///< Cache of the vertical scrollbar
350 static std::string content_type_strs
[CONTENT_TYPE_END
]; ///< Cached strings for all content types.
352 /** Search external websites for content */
353 void OpenExternalSearch()
358 url
+= "https://grfsearch.openttd.org/?";
360 if (this->auto_select
) {
361 url
+= "do=searchgrfid&q=";
364 for (const ContentInfo
*ci
: this->content
) {
365 if (ci
->state
!= ContentInfo::DOES_NOT_EXIST
) continue;
367 if (!first
) url
.push_back(',');
370 fmt::format_to(std::back_inserter(url
), "{:08X}:{}", ci
->unique_id
, FormatArrayAsHex(ci
->md5sum
));
373 url
+= "do=searchtext&q=";
375 /* Escape search term */
376 for (const char *search
= this->filter_editbox
.text
.buf
; *search
!= '\0'; search
++) {
378 if (*search
== '\'' || *search
== '"') continue;
380 /* Escape special chars, such as &%,= */
381 if (*search
< 0x30) {
382 fmt::format_to(std::back_inserter(url
), "%{:02X}", *search
);
384 url
.push_back(*search
);
393 * Callback function for disclaimer about entering external websites.
395 static void ExternalSearchDisclaimerCallback(Window
*w
, bool accepted
)
398 _accepted_external_search
= true;
399 ((NetworkContentListWindow
*)w
)->OpenExternalSearch();
404 * (Re)build the network game list as its amount has changed because
405 * an item has been added or deleted for example
407 void BuildContentList()
409 if (!this->content
.NeedRebuild()) return;
411 /* Create temporary array of games to use for listing */
412 this->content
.clear();
414 bool all_available
= true;
416 for (ConstContentIterator iter
= _network_content_client
.Begin(); iter
!= _network_content_client
.End(); iter
++) {
417 if ((*iter
)->state
== ContentInfo::DOES_NOT_EXIST
) all_available
= false;
418 this->content
.push_back(*iter
);
421 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL
, this->auto_select
&& all_available
);
423 this->FilterContentList();
424 this->content
.shrink_to_fit();
425 this->content
.RebuildDone();
426 this->SortContentList();
428 this->vscroll
->SetCount(this->content
.size()); // Update the scrollbar
429 this->ScrollToSelected();
432 /** Sort content by name. */
433 static bool NameSorter(const ContentInfo
* const &a
, const ContentInfo
* const &b
)
435 return StrNaturalCompare(a
->name
, b
->name
, true) < 0; // Sort by name (natural sorting).
438 /** Sort content by type. */
439 static bool TypeSorter(const ContentInfo
* const &a
, const ContentInfo
* const &b
)
442 if (a
->type
!= b
->type
) {
443 r
= StrNaturalCompare(content_type_strs
[a
->type
], content_type_strs
[b
->type
]);
445 if (r
== 0) return NameSorter(a
, b
);
449 /** Sort content by state. */
450 static bool StateSorter(const ContentInfo
* const &a
, const ContentInfo
* const &b
)
452 int r
= a
->state
- b
->state
;
453 if (r
== 0) return TypeSorter(a
, b
);
457 /** Sort the content list */
458 void SortContentList()
460 if (!this->content
.Sort()) return;
462 int idx
= find_index(this->content
, this->selected
);
463 if (idx
>= 0) this->list_pos
= idx
;
466 /** Filter content by tags/name */
467 static bool CDECL
TagNameFilter(const ContentInfo
* const *a
, ContentListFilterData
&filter
)
469 filter
.string_filter
.ResetState();
470 for (auto &tag
: (*a
)->tags
) filter
.string_filter
.AddLine(tag
);
472 filter
.string_filter
.AddLine((*a
)->name
);
473 return filter
.string_filter
.GetState();
476 /** Filter content by type, but still show content selected for download. */
477 static bool CDECL
TypeOrSelectedFilter(const ContentInfo
* const *a
, ContentListFilterData
&filter
)
479 if (filter
.types
.none()) return true;
480 if (filter
.types
[(*a
)->type
]) return true;
481 return ((*a
)->state
== ContentInfo::SELECTED
|| (*a
)->state
== ContentInfo::AUTOSELECTED
);
484 /** Filter the content list */
485 void FilterContentList()
488 bool changed
= false;
489 if (!this->filter_data
.string_filter
.IsEmpty()) {
490 this->content
.SetFilterType(CONTENT_FILTER_TEXT
);
491 changed
|= this->content
.Filter(this->filter_data
);
493 if (this->filter_data
.types
.any()) {
494 this->content
.SetFilterType(CONTENT_FILTER_TYPE_OR_SELECTED
);
495 changed
|= this->content
.Filter(this->filter_data
);
497 if (!changed
) return;
499 /* update list position */
500 int idx
= find_index(this->content
, this->selected
);
502 this->list_pos
= idx
;
506 /* previously selected item not in list anymore */
507 this->selected
= nullptr;
512 * Update filter state based on current window state.
513 * @return true if filter state was changed, otherwise false.
515 bool UpdateFilterState()
517 Filtering old_params
= this->content
.GetFiltering();
518 bool new_state
= !this->filter_data
.string_filter
.IsEmpty() || this->filter_data
.types
.any();
519 if (new_state
!= old_params
.state
) {
520 this->content
.SetFilterState(new_state
);
522 return new_state
!= old_params
.state
;
525 /** Make sure that the currently selected content info is within the visible part of the matrix */
526 void ScrollToSelected()
528 if (this->selected
== nullptr) return;
530 this->vscroll
->ScrollTowards(this->list_pos
);
533 friend void BuildContentTypeStringList();
536 * Create the content list window.
537 * @param desc the window description to pass to Window's constructor.
538 * @param select_all Whether the select all button is allowed or not.
539 * @param types the main type of content to display or #CONTENT_TYPE_END.
540 * When a type other than #CONTENT_TYPE_END is given, dependencies of
541 * other types are only shown when content that depend on them are
544 NetworkContentListWindow(WindowDesc
*desc
, bool select_all
, const std::bitset
<CONTENT_TYPE_END
> &types
) :
546 auto_select(select_all
),
547 filter_editbox(EDITBOX_MAX_SIZE
),
551 this->CreateNestedTree();
552 this->vscroll
= this->GetScrollbar(WID_NCL_SCROLLBAR
);
553 this->FinishInitNested(WN_NETWORK_WINDOW_CONTENT_LIST
);
555 this->GetWidget
<NWidgetStacked
>(WID_NCL_SEL_ALL_UPDATE
)->SetDisplayedPlane(select_all
);
557 this->querystrings
[WID_NCL_FILTER
] = &this->filter_editbox
;
558 this->filter_editbox
.cancel_button
= QueryString::ACTION_CLEAR
;
559 this->SetFocusedWidget(WID_NCL_FILTER
);
560 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL
, this->auto_select
);
561 this->filter_data
.types
= types
;
563 _network_content_client
.AddCallback(this);
564 this->content
.SetListing(this->last_sorting
);
565 this->content
.SetFiltering(this->last_filtering
);
566 this->content
.SetSortFuncs(this->sorter_funcs
);
567 this->content
.SetFilterFuncs(this->filter_funcs
);
568 this->UpdateFilterState();
569 this->content
.ForceRebuild();
570 this->FilterContentList();
571 this->SortContentList();
572 this->InvalidateData();
575 void Close([[maybe_unused
]] int data
= 0) override
577 _network_content_client
.RemoveCallback(this);
578 this->Window::Close();
581 void OnInit() override
583 this->checkbox_size
= maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY
), GetSpriteSize(SPR_BOX_CHECKED
)), GetSpriteSize(SPR_BLOT
));
586 void UpdateWidgetSize(WidgetID widget
, Dimension
*size
, [[maybe_unused
]] const Dimension
&padding
, [[maybe_unused
]] Dimension
*fill
, [[maybe_unused
]] Dimension
*resize
) override
589 case WID_NCL_CHECKBOX
:
590 size
->width
= this->checkbox_size
.width
+ padding
.width
;
595 for (int i
= CONTENT_TYPE_BEGIN
; i
< CONTENT_TYPE_END
; i
++) {
596 d
= maxdim(d
, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS
+ i
- CONTENT_TYPE_BASE_GRAPHICS
));
598 size
->width
= d
.width
+ padding
.width
;
603 resize
->height
= std::max(this->checkbox_size
.height
, (uint
)GetCharacterHeight(FS_NORMAL
)) + padding
.height
;
604 size
->height
= 10 * resize
->height
;
610 void DrawWidget(const Rect
&r
, WidgetID widget
) const override
613 case WID_NCL_DETAILS
:
614 this->DrawDetails(r
);
623 void OnPaint() override
625 const SortButtonState arrow
= this->content
.IsDescSortOrder() ? SBS_DOWN
: SBS_UP
;
627 if (this->content
.NeedRebuild()) {
628 this->BuildContentList();
633 switch (this->content
.SortType()) {
634 case WID_NCL_CHECKBOX
- WID_NCL_CHECKBOX
: this->DrawSortButtonState(WID_NCL_CHECKBOX
, arrow
); break;
635 case WID_NCL_TYPE
- WID_NCL_CHECKBOX
: this->DrawSortButtonState(WID_NCL_TYPE
, arrow
); break;
636 case WID_NCL_NAME
- WID_NCL_CHECKBOX
: this->DrawSortButtonState(WID_NCL_NAME
, arrow
); break;
641 * Draw/fill the matrix with the list of content to download.
642 * @param r The boundaries of the matrix.
644 void DrawMatrix(const Rect
&r
) const
646 Rect checkbox
= this->GetWidget
<NWidgetBase
>(WID_NCL_CHECKBOX
)->GetCurrentRect();
647 Rect name
= this->GetWidget
<NWidgetBase
>(WID_NCL_NAME
)->GetCurrentRect().Shrink(WidgetDimensions::scaled
.framerect
);
648 Rect type
= this->GetWidget
<NWidgetBase
>(WID_NCL_TYPE
)->GetCurrentRect();
650 /* Fill the matrix with the information */
651 int sprite_y_offset
= (this->resize
.step_height
- this->checkbox_size
.height
) / 2;
652 int text_y_offset
= (this->resize
.step_height
- GetCharacterHeight(FS_NORMAL
)) / 2;
654 Rect mr
= r
.WithHeight(this->resize
.step_height
);
655 auto iter
= this->content
.begin() + this->vscroll
->GetPosition();
656 size_t last
= this->vscroll
->GetPosition() + this->vscroll
->GetCapacity();
657 auto end
= (last
< this->content
.size()) ? this->content
.begin() + last
: this->content
.end();
659 for (/**/; iter
!= end
; iter
++) {
660 const ContentInfo
*ci
= *iter
;
662 if (ci
== this->selected
) GfxFillRect(mr
.Shrink(WidgetDimensions::scaled
.bevel
), PC_GREY
);
665 SpriteID pal
= PAL_NONE
;
667 case ContentInfo::UNSELECTED
: sprite
= SPR_BOX_EMPTY
; break;
668 case ContentInfo::SELECTED
: sprite
= SPR_BOX_CHECKED
; break;
669 case ContentInfo::AUTOSELECTED
: sprite
= SPR_BOX_CHECKED
; break;
670 case ContentInfo::ALREADY_HERE
: sprite
= SPR_BLOT
; pal
= PALETTE_TO_GREEN
; break;
671 case ContentInfo::DOES_NOT_EXIST
: sprite
= SPR_BLOT
; pal
= PALETTE_TO_RED
; break;
672 default: NOT_REACHED();
674 DrawSprite(sprite
, pal
, checkbox
.left
+ (sprite
== SPR_BLOT
? 3 : 2), mr
.top
+ sprite_y_offset
+ (sprite
== SPR_BLOT
? 0 : 1));
676 StringID str
= STR_CONTENT_TYPE_BASE_GRAPHICS
+ ci
->type
- CONTENT_TYPE_BASE_GRAPHICS
;
677 DrawString(type
.left
, type
.right
, mr
.top
+ text_y_offset
, str
, TC_BLACK
, SA_HOR_CENTER
);
679 DrawString(name
.left
, name
.right
, mr
.top
+ text_y_offset
, ci
->name
, TC_BLACK
);
680 mr
= mr
.Translate(0, this->resize
.step_height
);
685 * Helper function to draw the details part of this window.
686 * @param r the rectangle to stay within while drawing
688 void DrawDetails(const Rect
&r
) const
690 /* Height for the title banner */
691 int HEADER_HEIGHT
= 3 * GetCharacterHeight(FS_NORMAL
) + WidgetDimensions::scaled
.frametext
.Vertical();
693 Rect hr
= r
.WithHeight(HEADER_HEIGHT
).Shrink(WidgetDimensions::scaled
.frametext
);
694 Rect tr
= r
.Shrink(WidgetDimensions::scaled
.frametext
);
695 tr
.top
+= HEADER_HEIGHT
;
697 /* Create the nice grayish rectangle at the details top */
698 GfxFillRect(r
.WithHeight(HEADER_HEIGHT
).Shrink(WidgetDimensions::scaled
.bevel
.left
, WidgetDimensions::scaled
.bevel
.top
, WidgetDimensions::scaled
.bevel
.right
, 0), PC_DARK_BLUE
);
699 DrawString(hr
.left
, hr
.right
, hr
.top
, STR_CONTENT_DETAIL_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
);
701 /* Draw the total download size */
702 SetDParam(0, this->filesize_sum
);
703 DrawString(tr
.left
, tr
.right
, tr
.bottom
- GetCharacterHeight(FS_NORMAL
) + 1, STR_CONTENT_TOTAL_DOWNLOAD_SIZE
);
705 if (this->selected
== nullptr) return;
707 /* And fill the rest of the details when there's information to place there */
708 DrawStringMultiLine(hr
.left
, hr
.right
, hr
.top
+ GetCharacterHeight(FS_NORMAL
), hr
.bottom
, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED
+ this->selected
->state
, TC_FROMSTRING
, SA_CENTER
);
710 /* Also show the total download size, so keep some space from the bottom */
711 tr
.bottom
-= GetCharacterHeight(FS_NORMAL
) + WidgetDimensions::scaled
.vsep_wide
;
713 if (this->selected
->upgrade
) {
714 SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS
+ this->selected
->type
- CONTENT_TYPE_BASE_GRAPHICS
);
715 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_UPDATE
);
716 tr
.top
+= WidgetDimensions::scaled
.vsep_wide
;
719 SetDParamStr(0, this->selected
->name
);
720 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_NAME
);
722 if (!this->selected
->version
.empty()) {
723 SetDParamStr(0, this->selected
->version
);
724 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_VERSION
);
727 if (!this->selected
->description
.empty()) {
728 SetDParamStr(0, this->selected
->description
);
729 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_DESCRIPTION
);
732 if (!this->selected
->url
.empty()) {
733 SetDParamStr(0, this->selected
->url
);
734 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_URL
);
737 SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS
+ this->selected
->type
- CONTENT_TYPE_BASE_GRAPHICS
);
738 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_TYPE
);
740 tr
.top
+= WidgetDimensions::scaled
.vsep_wide
;
741 SetDParam(0, this->selected
->filesize
);
742 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_FILESIZE
);
744 if (!this->selected
->dependencies
.empty()) {
745 /* List dependencies */
747 for (auto &cid
: this->selected
->dependencies
) {
748 /* Try to find the dependency */
749 ConstContentIterator iter
= _network_content_client
.Begin();
750 for (; iter
!= _network_content_client
.End(); iter
++) {
751 const ContentInfo
*ci
= *iter
;
752 if (ci
->id
!= cid
) continue;
754 if (!buf
.empty()) buf
+= ", ";
755 buf
+= (*iter
)->name
;
759 SetDParamStr(0, buf
);
760 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_DEPENDENCIES
);
763 if (!this->selected
->tags
.empty()) {
766 for (auto &tag
: this->selected
->tags
) {
767 if (!buf
.empty()) buf
+= ", ";
770 SetDParamStr(0, buf
);
771 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_TAGS
);
774 if (this->selected
->IsSelected()) {
775 /* When selected show all manually selected content that depends on this */
776 ConstContentVector tree
;
777 _network_content_client
.ReverseLookupTreeDependency(tree
, this->selected
);
780 for (const ContentInfo
*ci
: tree
) {
781 if (ci
== this->selected
|| ci
->state
!= ContentInfo::SELECTED
) continue;
783 if (!buf
.empty()) buf
+= ", ";
787 SetDParamStr(0, buf
);
788 tr
.top
= DrawStringMultiLine(tr
, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF
);
793 void OnClick([[maybe_unused
]] Point pt
, WidgetID widget
, [[maybe_unused
]] int click_count
) override
795 if (widget
>= WID_NCL_TEXTFILE
&& widget
< WID_NCL_TEXTFILE
+ TFT_CONTENT_END
) {
796 if (this->selected
== nullptr || this->selected
->state
!= ContentInfo::ALREADY_HERE
) return;
798 ShowContentTextfileWindow((TextfileType
)(widget
- WID_NCL_TEXTFILE
), this->selected
);
803 case WID_NCL_MATRIX
: {
804 auto it
= this->vscroll
->GetScrolledItemFromWidget(this->content
, pt
.y
, this, WID_NCL_MATRIX
);
805 if (it
== this->content
.end()) return; // click out of bounds
807 this->selected
= *it
;
808 this->list_pos
= it
- this->content
.begin();
810 const NWidgetBase
*checkbox
= this->GetWidget
<NWidgetBase
>(WID_NCL_CHECKBOX
);
811 if (click_count
> 1 || IsInsideBS(pt
.x
, checkbox
->pos_x
, checkbox
->current_x
)) {
812 _network_content_client
.ToggleSelectedState(this->selected
);
813 this->content
.ForceResort();
816 if (this->filter_data
.types
.any()) {
817 this->content
.ForceRebuild();
820 this->InvalidateData();
824 case WID_NCL_CHECKBOX
:
827 if (this->content
.SortType() == widget
- WID_NCL_CHECKBOX
) {
828 this->content
.ToggleSortOrder();
829 if (!this->content
.empty()) this->list_pos
= (int)this->content
.size() - this->list_pos
- 1;
831 this->content
.SetSortType(widget
- WID_NCL_CHECKBOX
);
832 this->content
.ForceResort();
833 this->SortContentList();
835 this->ScrollToSelected();
836 this->InvalidateData();
839 case WID_NCL_SELECT_ALL
:
840 _network_content_client
.SelectAll();
841 this->InvalidateData();
844 case WID_NCL_SELECT_UPDATE
:
845 _network_content_client
.SelectUpgrade();
846 this->InvalidateData();
849 case WID_NCL_UNSELECT
:
850 _network_content_client
.UnselectAll();
851 this->InvalidateData();
858 case WID_NCL_OPEN_URL
:
859 if (this->selected
!= nullptr) {
860 OpenBrowser(this->selected
->url
);
864 case WID_NCL_DOWNLOAD
:
865 if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW
, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
) == nullptr) new NetworkContentDownloadStatusWindow();
868 case WID_NCL_SEARCH_EXTERNAL
:
869 if (_accepted_external_search
) {
870 this->OpenExternalSearch();
872 ShowQuery(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION
, STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER
, this, ExternalSearchDisclaimerCallback
);
878 EventState
OnKeyPress([[maybe_unused
]] char32_t key
, uint16_t keycode
) override
880 if (this->vscroll
->UpdateListPositionOnKeyPress(this->list_pos
, keycode
) == ES_NOT_HANDLED
) {
884 if (keycode
== WKC_RETURN
|| !IsWidgetFocused(WID_NCL_FILTER
)) {
885 if (this->selected
!= nullptr) {
886 _network_content_client
.ToggleSelectedState(this->selected
);
887 this->content
.ForceResort();
888 this->InvalidateData();
890 if (this->filter_data
.types
.any()) {
891 this->content
.ForceRebuild();
892 this->InvalidateData();
896 /* space is pressed and filter is focused. */
900 return ES_NOT_HANDLED
;
904 if (this->content
.empty()) {
905 if (this->UpdateFilterState()) {
906 this->content
.ForceRebuild();
907 this->InvalidateData();
912 this->selected
= this->content
[this->list_pos
];
914 if (this->UpdateFilterState()) {
915 this->content
.ForceRebuild();
917 /* Scroll to the new content if it is outside the current range. */
918 this->ScrollToSelected();
922 this->InvalidateData();
926 void OnEditboxChanged(WidgetID wid
) override
928 if (wid
== WID_NCL_FILTER
) {
929 this->filter_data
.string_filter
.SetFilterTerm(this->filter_editbox
.text
.buf
);
930 this->UpdateFilterState();
931 this->content
.ForceRebuild();
932 this->InvalidateData();
936 void OnResize() override
938 this->vscroll
->SetCapacityFromWidget(this, WID_NCL_MATRIX
);
941 void OnReceiveContentInfo(const ContentInfo
*rci
) override
943 if (this->auto_select
&& !rci
->IsSelected()) _network_content_client
.ToggleSelectedState(rci
);
944 this->content
.ForceRebuild();
945 this->InvalidateData(0, false);
948 void OnDownloadComplete(ContentID
) override
950 this->content
.ForceResort();
951 this->InvalidateData();
954 void OnConnect(bool success
) override
957 ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT
, INVALID_STRING_ID
, WL_ERROR
);
962 this->InvalidateData();
966 * Some data on this window has become invalid.
967 * @param data Information about the changed data.
968 * @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.
970 void OnInvalidateData([[maybe_unused
]] int data
= 0, [[maybe_unused
]] bool gui_scope
= true) override
972 if (!gui_scope
) return;
973 if (this->content
.NeedRebuild()) this->BuildContentList();
975 /* To sum all the bytes we intend to download */
976 this->filesize_sum
= 0;
977 bool show_select_all
= false;
978 bool show_select_upgrade
= false;
979 for (const ContentInfo
*ci
: this->content
) {
981 case ContentInfo::SELECTED
:
982 case ContentInfo::AUTOSELECTED
:
983 this->filesize_sum
+= ci
->filesize
;
986 case ContentInfo::UNSELECTED
:
987 show_select_all
= true;
988 show_select_upgrade
|= ci
->upgrade
;
996 /* If data == 2 then the status window caused this OnInvalidate */
997 this->SetWidgetDisabledState(WID_NCL_DOWNLOAD
, this->filesize_sum
== 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW
, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
) != nullptr && data
!= 2));
998 this->SetWidgetDisabledState(WID_NCL_UNSELECT
, this->filesize_sum
== 0);
999 this->SetWidgetDisabledState(WID_NCL_SELECT_ALL
, !show_select_all
);
1000 this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE
, !show_select_upgrade
);
1001 this->SetWidgetDisabledState(WID_NCL_OPEN_URL
, this->selected
== nullptr || this->selected
->url
.empty());
1002 for (TextfileType tft
= TFT_CONTENT_BEGIN
; tft
< TFT_CONTENT_END
; tft
++) {
1003 this->SetWidgetDisabledState(WID_NCL_TEXTFILE
+ tft
, this->selected
== nullptr || this->selected
->state
!= ContentInfo::ALREADY_HERE
|| !this->selected
->GetTextfile(tft
).has_value());
1006 this->GetWidget
<NWidgetCore
>(WID_NCL_CANCEL
)->widget_data
= this->filesize_sum
== 0 ? STR_AI_SETTINGS_CLOSE
: STR_AI_LIST_CANCEL
;
1010 Listing
NetworkContentListWindow::last_sorting
= {false, 1};
1011 Filtering
NetworkContentListWindow::last_filtering
= {false, 0};
1013 NetworkContentListWindow::GUIContentList::SortFunction
* const NetworkContentListWindow::sorter_funcs
[] = {
1019 NetworkContentListWindow::GUIContentList::FilterFunction
* const NetworkContentListWindow::filter_funcs
[] = {
1021 &TypeOrSelectedFilter
,
1024 std::string
NetworkContentListWindow::content_type_strs
[CONTENT_TYPE_END
];
1027 * Build array of all strings corresponding to the content types.
1029 void BuildContentTypeStringList()
1031 for (int i
= CONTENT_TYPE_BEGIN
; i
< CONTENT_TYPE_END
; i
++) {
1032 NetworkContentListWindow::content_type_strs
[i
] = GetString(STR_CONTENT_TYPE_BASE_GRAPHICS
+ i
- CONTENT_TYPE_BASE_GRAPHICS
);
1036 /** The widgets for the content list. */
1037 static constexpr NWidgetPart _nested_network_content_list_widgets
[] = {
1038 NWidget(NWID_HORIZONTAL
),
1039 NWidget(WWT_CLOSEBOX
, COLOUR_LIGHT_BLUE
),
1040 NWidget(WWT_CAPTION
, COLOUR_LIGHT_BLUE
), SetDataTip(STR_CONTENT_TITLE
, STR_NULL
),
1041 NWidget(WWT_DEFSIZEBOX
, COLOUR_LIGHT_BLUE
),
1043 NWidget(WWT_PANEL
, COLOUR_LIGHT_BLUE
, WID_NCL_BACKGROUND
),
1044 NWidget(NWID_VERTICAL
), SetPIP(0, WidgetDimensions::unscaled
.vsep_wide
, 0), SetPadding(WidgetDimensions::unscaled
.sparse_resize
),
1046 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(0, WidgetDimensions::unscaled
.hsep_wide
, 0),
1047 NWidget(WWT_TEXT
, COLOUR_LIGHT_BLUE
, WID_NCL_FILTER_CAPT
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_CONTENT_FILTER_TITLE
, STR_NULL
), SetAlignment(SA_RIGHT
| SA_VERT_CENTER
),
1048 NWidget(WWT_EDITBOX
, COLOUR_LIGHT_BLUE
, WID_NCL_FILTER
), SetFill(1, 0), SetResize(1, 0),
1049 SetDataTip(STR_LIST_FILTER_OSKTITLE
, STR_LIST_FILTER_TOOLTIP
),
1051 /* Lists and info. */
1052 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(0, WidgetDimensions::unscaled
.hsep_wide
, 0),
1054 NWidget(NWID_VERTICAL
), SetPIP(0, WidgetDimensions::unscaled
.vsep_sparse
, 0),
1055 NWidget(NWID_HORIZONTAL
),
1056 NWidget(NWID_VERTICAL
),
1057 NWidget(NWID_HORIZONTAL
),
1058 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_CHECKBOX
), SetMinimalSize(13, 1), SetDataTip(STR_EMPTY
, STR_NULL
),
1059 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_TYPE
),
1060 SetDataTip(STR_CONTENT_TYPE_CAPTION
, STR_CONTENT_TYPE_CAPTION_TOOLTIP
),
1061 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_NAME
), SetResize(1, 0), SetFill(1, 0),
1062 SetDataTip(STR_CONTENT_NAME_CAPTION
, STR_CONTENT_NAME_CAPTION_TOOLTIP
),
1064 NWidget(WWT_MATRIX
, COLOUR_LIGHT_BLUE
, WID_NCL_MATRIX
), SetResize(1, 14), SetFill(1, 1), SetScrollbar(WID_NCL_SCROLLBAR
), SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP
),
1066 NWidget(NWID_VSCROLLBAR
, COLOUR_LIGHT_BLUE
, WID_NCL_SCROLLBAR
),
1068 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(0, WidgetDimensions::unscaled
.hsep_wide
, 0),
1069 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_NCL_SEL_ALL_UPDATE
),
1070 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_SELECT_UPDATE
), SetResize(1, 0), SetFill(1, 0),
1071 SetDataTip(STR_CONTENT_SELECT_UPDATES_CAPTION
, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP
),
1072 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_SELECT_ALL
), SetResize(1, 0), SetFill(1, 0),
1073 SetDataTip(STR_CONTENT_SELECT_ALL_CAPTION
, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP
),
1075 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_UNSELECT
), SetResize(1, 0), SetFill(1, 0),
1076 SetDataTip(STR_CONTENT_UNSELECT_ALL_CAPTION
, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP
),
1080 NWidget(NWID_VERTICAL
), SetPIP(0, WidgetDimensions::unscaled
.vsep_sparse
, 0),
1081 NWidget(WWT_PANEL
, COLOUR_LIGHT_BLUE
, WID_NCL_DETAILS
), SetResize(1, 1), SetFill(1, 1),
1083 NWidget(NWID_VERTICAL
),
1084 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1085 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_OPEN_URL
), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL
, STR_CONTENT_OPEN_URL_TOOLTIP
),
1086 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_TEXTFILE
+ TFT_README
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README
, STR_TEXTFILE_VIEW_README_TOOLTIP
),
1088 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1089 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_TEXTFILE
+ TFT_CHANGELOG
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG
, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP
),
1090 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_TEXTFILE
+ TFT_LICENSE
), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE
, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP
),
1096 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(0, WidgetDimensions::unscaled
.hsep_wide
, 0),
1097 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_SEARCH_EXTERNAL
), SetResize(1, 0), SetFill(1, 0),
1098 SetDataTip(STR_CONTENT_SEARCH_EXTERNAL
, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP
),
1099 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(0, WidgetDimensions::unscaled
.hsep_wide
, 0),
1100 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_CANCEL
), SetResize(1, 0), SetFill(1, 0),
1101 SetDataTip(STR_BUTTON_CANCEL
, STR_NULL
),
1102 NWidget(WWT_PUSHTXTBTN
, COLOUR_WHITE
, WID_NCL_DOWNLOAD
), SetResize(1, 0), SetFill(1, 0),
1103 SetDataTip(STR_CONTENT_DOWNLOAD_CAPTION
, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP
),
1107 /* Resize button. */
1108 NWidget(NWID_HORIZONTAL
),
1109 NWidget(NWID_SPACER
), SetFill(1, 0), SetResize(1, 0),
1110 NWidget(WWT_RESIZEBOX
, COLOUR_LIGHT_BLUE
), SetDataTip(RWV_HIDE_BEVEL
, STR_TOOLTIP_RESIZE
),
1115 /** Window description of the content list */
1116 static WindowDesc
_network_content_list_desc(__FILE__
, __LINE__
,
1117 WDP_CENTER
, "list_content", 630, 460,
1118 WC_NETWORK_WINDOW
, WC_NONE
,
1120 std::begin(_nested_network_content_list_widgets
), std::end(_nested_network_content_list_widgets
)
1124 * Show the content list window with a given set of content
1125 * @param cv the content to show, or nullptr when it has to search for itself
1126 * @param type1 the first type to (only) show or #CONTENT_TYPE_END to show all.
1127 * @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.
1128 * If type2 != #CONTENT_TYPE_END, then type1 != type2 must be true.
1130 void ShowNetworkContentListWindow(ContentVector
*cv
, ContentType type1
, ContentType type2
)
1132 #if defined(WITH_ZLIB)
1133 std::bitset
<CONTENT_TYPE_END
> types
;
1134 _network_content_client
.Clear();
1135 if (cv
== nullptr) {
1136 assert(type1
!= CONTENT_TYPE_END
|| type2
== CONTENT_TYPE_END
);
1137 assert(type1
== CONTENT_TYPE_END
|| type1
!= type2
);
1138 _network_content_client
.RequestContentList(type1
);
1139 if (type2
!= CONTENT_TYPE_END
) _network_content_client
.RequestContentList(type2
);
1141 if (type1
!= CONTENT_TYPE_END
) types
[type1
] = true;
1142 if (type2
!= CONTENT_TYPE_END
) types
[type2
] = true;
1144 _network_content_client
.RequestContentList(cv
, true);
1147 CloseWindowById(WC_NETWORK_WINDOW
, WN_NETWORK_WINDOW_CONTENT_LIST
);
1148 new NetworkContentListWindow(&_network_content_list_desc
, cv
!= nullptr, types
);
1150 ShowErrorMessage(STR_CONTENT_NO_ZLIB
, STR_CONTENT_NO_ZLIB_SUB
, WL_ERROR
);
1151 /* Connection failed... clean up the mess */
1152 if (cv
!= nullptr) {
1153 for (ContentInfo
*ci
: *cv
) delete ci
;
1155 #endif /* WITH_ZLIB */