OpenTTD Source  14.0-beta1
network_content_gui.cpp
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "../gfx_func.h"
13 #include "../window_func.h"
14 #include "../error.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"
24 #include "../fios.h"
25 #include "network_content_gui.h"
26 
27 
28 #include "table/strings.h"
29 #include "../table/sprites.h"
30 
31 #include <bitset>
32 
33 #include "../safeguards.h"
34 
35 
37 static bool _accepted_external_search = false;
38 
39 
42  const ContentInfo *ci;
43 
45  {
46  this->ConstructWindow();
47 
48  auto textfile = this->ci->GetTextfile(file_type);
49  this->LoadTextfile(textfile.value(), GetContentInfoSubDir(this->ci->type));
50  }
51 
52  StringID GetTypeString() const
53  {
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();
66  }
67  }
68 
69  void SetStringParameters(WidgetID widget) const override
70  {
71  if (widget == WID_TF_CAPTION) {
72  SetDParam(0, this->GetTypeString());
73  SetDParamStr(1, this->ci->name);
74  }
75  }
76 };
77 
78 void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci)
79 {
80  CloseWindowById(WC_TEXTFILE, file_type);
81  new ContentTextfileWindow(file_type, ci);
82 }
83 
86  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
87  NWidget(WWT_PANEL, COLOUR_GREY),
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),
92  EndContainer(),
93  EndContainer(),
94 };
95 
98  WDP_CENTER, nullptr, 0, 0,
100  WDF_MODAL,
102 );
103 
105  Window(desc), downloaded_bytes(0), downloaded_files(0), cur_id(UINT32_MAX)
106 {
109 
111 }
112 
113 void BaseNetworkContentDownloadStatusWindow::Close([[maybe_unused]] int data)
114 {
116  this->Window::Close();
117 }
118 
119 void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize)
120 {
121  switch (widget) {
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' */
130  break;
131 
134  break;
135  }
136 }
137 
138 void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, WidgetID widget) const
139 {
140  switch (widget) {
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);
150  break;
151  }
152 
153  case WID_NCDS_PROGRESS_TEXT: {
154  StringID str;
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;
162  } else {
163  str = STR_CONTENT_DOWNLOAD_INITIALISE;
164  }
165  DrawStringMultiLine(r, str, TC_FROMSTRING, SA_CENTER);
166  break;
167  }
168  }
169 }
170 
171 void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
172 {
173  if (ci->id != this->cur_id) {
174  this->name = ci->filename;
175  this->cur_id = ci->id;
176  this->downloaded_files++;
177  }
178 
179  /* A negative value means we are resetting; for example, when retrying or using a fallback. */
180  if (bytes < 0) {
181  this->downloaded_bytes = 0;
182  } else {
183  this->downloaded_bytes += bytes;
184  }
185 
186  this->SetDirty();
187 }
188 
189 
192 private:
193  std::vector<ContentType> receivedTypes;
194 
195 public:
201  {
203  }
204 
205  void Close([[maybe_unused]] int data = 0) override
206  {
208  for (auto ctype : this->receivedTypes) {
209  switch (ctype) {
210  case CONTENT_TYPE_AI:
212  /* AI::Rescan calls the scanner. */
213  break;
214  case CONTENT_TYPE_GAME:
216  /* Game::Rescan calls the scanner. */
217  break;
218 
222  mode |= TarScanner::BASESET;
223  break;
224 
225  case CONTENT_TYPE_NEWGRF:
226  /* ScanNewGRFFiles calls the scanner. */
227  break;
228 
231  mode |= TarScanner::SCENARIO;
232  break;
233 
234  default:
235  break;
236  }
237  }
238 
239  TarScanner::DoScan(mode);
240 
241  /* Tell all the backends about what we've downloaded */
242  for (auto ctype : this->receivedTypes) {
243  switch (ctype) {
244  case CONTENT_TYPE_AI:
246  AI::Rescan();
247  break;
248 
249  case CONTENT_TYPE_GAME:
251  Game::Rescan();
252  break;
253 
257  break;
258 
262  break;
263 
267  break;
268 
269  case CONTENT_TYPE_NEWGRF:
271  break;
272 
275  ScanScenarios();
277  break;
278 
279  default:
280  break;
281  }
282  }
283 
284  /* Always invalidate the download window; tell it we are going to be gone */
286 
287  this->BaseNetworkContentDownloadStatusWindow::Close();
288  }
289 
290  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
291  {
292  if (widget == WID_NCDS_CANCELOK) {
293  if (this->downloaded_bytes != this->total_bytes) {
295  this->Close();
296  } else {
297  /* If downloading succeeded, close the online content window. This will close
298  * the current window as well. */
300  }
301  }
302  }
303 
304  void OnDownloadProgress(const ContentInfo *ci, int bytes) override
305  {
306  BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
307  include(this->receivedTypes, ci->type);
308 
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;
312  }
313  }
314 };
315 
319  std::bitset<CONTENT_TYPE_END> types;
320 };
321 
326 };
327 
332 
333  static const uint EDITBOX_MAX_SIZE = 50;
334 
340  bool auto_select;
344 
346  int list_pos;
349 
350  static std::string content_type_strs[CONTENT_TYPE_END];
351 
354  {
355  std::string url;
356  url.reserve(1024);
357 
358  url += "https://grfsearch.openttd.org/?";
359 
360  if (this->auto_select) {
361  url += "do=searchgrfid&q=";
362 
363  bool first = true;
364  for (const ContentInfo *ci : this->content) {
365  if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
366 
367  if (!first) url.push_back(',');
368  first = false;
369 
370  fmt::format_to(std::back_inserter(url), "{:08X}:{}", ci->unique_id, FormatArrayAsHex(ci->md5sum));
371  }
372  } else {
373  url += "do=searchtext&q=";
374 
375  /* Escape search term */
376  for (const char *search = this->filter_editbox.text.buf; *search != '\0'; search++) {
377  /* Remove quotes */
378  if (*search == '\'' || *search == '"') continue;
379 
380  /* Escape special chars, such as &%,= */
381  if (*search < 0x30) {
382  fmt::format_to(std::back_inserter(url), "%{:02X}", *search);
383  } else {
384  url.push_back(*search);
385  }
386  }
387  }
388 
389  OpenBrowser(url);
390  }
391 
395  static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
396  {
397  if (accepted) {
399  ((NetworkContentListWindow*)w)->OpenExternalSearch();
400  }
401  }
402 
408  {
409  if (!this->content.NeedRebuild()) return;
410 
411  /* Create temporary array of games to use for listing */
412  this->content.clear();
413 
414  bool all_available = true;
415 
417  if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false;
418  this->content.push_back(*iter);
419  }
420 
421  this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
422 
423  this->FilterContentList();
424  this->content.shrink_to_fit();
425  this->content.RebuildDone();
426  this->SortContentList();
427 
428  this->vscroll->SetCount(this->content.size()); // Update the scrollbar
429  this->ScrollToSelected();
430  }
431 
433  static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
434  {
435  return StrNaturalCompare(a->name, b->name, true) < 0; // Sort by name (natural sorting).
436  }
437 
439  static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
440  {
441  int r = 0;
442  if (a->type != b->type) {
444  }
445  if (r == 0) return NameSorter(a, b);
446  return r < 0;
447  }
448 
450  static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
451  {
452  int r = a->state - b->state;
453  if (r == 0) return TypeSorter(a, b);
454  return r < 0;
455  }
456 
459  {
460  if (!this->content.Sort()) return;
461 
462  int idx = find_index(this->content, this->selected);
463  if (idx >= 0) this->list_pos = idx;
464  }
465 
467  static bool CDECL TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
468  {
469  filter.string_filter.ResetState();
470  for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag);
471 
472  filter.string_filter.AddLine((*a)->name);
473  return filter.string_filter.GetState();
474  }
475 
477  static bool CDECL TypeOrSelectedFilter(const ContentInfo * const *a, ContentListFilterData &filter)
478  {
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);
482  }
483 
486  {
487  /* Apply filters. */
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);
492  }
493  if (this->filter_data.types.any()) {
495  changed |= this->content.Filter(this->filter_data);
496  }
497  if (!changed) return;
498 
499  /* update list position */
500  int idx = find_index(this->content, this->selected);
501  if (idx >= 0) {
502  this->list_pos = idx;
503  return;
504  }
505 
506  /* previously selected item not in list anymore */
507  this->selected = nullptr;
508  this->list_pos = 0;
509  }
510 
516  {
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);
521  }
522  return new_state != old_params.state;
523  }
524 
527  {
528  if (this->selected == nullptr) return;
529 
530  this->vscroll->ScrollTowards(this->list_pos);
531  }
532 
533  friend void BuildContentTypeStringList();
534 public:
544  NetworkContentListWindow(WindowDesc *desc, bool select_all, const std::bitset<CONTENT_TYPE_END> &types) :
545  Window(desc),
546  auto_select(select_all),
548  selected(nullptr),
549  list_pos(0)
550  {
551  this->CreateNestedTree();
552  this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
554 
555  this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
556 
558  this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
560  this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
561  this->filter_data.types = types;
562 
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();
573  }
574 
575  void Close([[maybe_unused]] int data = 0) override
576  {
578  this->Window::Close();
579  }
580 
581  void OnInit() override
582  {
583  this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT));
584  }
585 
586  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
587  {
588  switch (widget) {
589  case WID_NCL_CHECKBOX:
590  size->width = this->checkbox_size.width + padding.width;
591  break;
592 
593  case WID_NCL_TYPE: {
594  Dimension d = *size;
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));
597  }
598  size->width = d.width + padding.width;
599  break;
600  }
601 
602  case WID_NCL_MATRIX:
603  resize->height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
604  size->height = 10 * resize->height;
605  break;
606  }
607  }
608 
609 
610  void DrawWidget(const Rect &r, WidgetID widget) const override
611  {
612  switch (widget) {
613  case WID_NCL_DETAILS:
614  this->DrawDetails(r);
615  break;
616 
617  case WID_NCL_MATRIX:
618  this->DrawMatrix(r);
619  break;
620  }
621  }
622 
623  void OnPaint() override
624  {
625  const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
626 
627  if (this->content.NeedRebuild()) {
628  this->BuildContentList();
629  }
630 
631  this->DrawWidgets();
632 
633  switch (this->content.SortType()) {
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;
637  }
638  }
639 
644  void DrawMatrix(const Rect &r) const
645  {
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();
649 
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;
653 
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();
658 
659  for (; iter != end; iter++) {
660  const ContentInfo *ci = *iter;
661 
662  if (ci == this->selected) GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), PC_GREY);
663 
664  SpriteID sprite;
665  SpriteID pal = PAL_NONE;
666  switch (ci->state) {
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();
673  }
674  DrawSprite(sprite, pal, checkbox.left + (sprite == SPR_BLOT ? 3 : 2), mr.top + sprite_y_offset + (sprite == SPR_BLOT ? 0 : 1));
675 
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);
678 
679  DrawString(name.left, name.right, mr.top + text_y_offset, ci->name, TC_BLACK);
680  mr = mr.Translate(0, this->resize.step_height);
681  }
682  }
683 
688  void DrawDetails(const Rect &r) const
689  {
690  /* Height for the title banner */
692 
693  Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.frametext);
694  Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
695  tr.top += HEADER_HEIGHT;
696 
697  /* Create the nice grayish rectangle at the details top */
699  DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
700 
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);
704 
705  if (this->selected == nullptr) return;
706 
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);
709 
710  /* Also show the total download size, so keep some space from the bottom */
712 
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);
717  }
718 
719  SetDParamStr(0, this->selected->name);
720  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_NAME);
721 
722  if (!this->selected->version.empty()) {
723  SetDParamStr(0, this->selected->version);
724  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_VERSION);
725  }
726 
727  if (!this->selected->description.empty()) {
728  SetDParamStr(0, this->selected->description);
729  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DESCRIPTION);
730  }
731 
732  if (!this->selected->url.empty()) {
733  SetDParamStr(0, this->selected->url);
734  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_URL);
735  }
736 
737  SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
738  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TYPE);
739 
741  SetDParam(0, this->selected->filesize);
742  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_FILESIZE);
743 
744  if (!this->selected->dependencies.empty()) {
745  /* List dependencies */
746  std::string buf;
747  for (auto &cid : this->selected->dependencies) {
748  /* Try to find the dependency */
750  for (; iter != _network_content_client.End(); iter++) {
751  const ContentInfo *ci = *iter;
752  if (ci->id != cid) continue;
753 
754  if (!buf.empty()) buf += ", ";
755  buf += (*iter)->name;
756  break;
757  }
758  }
759  SetDParamStr(0, buf);
760  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DEPENDENCIES);
761  }
762 
763  if (!this->selected->tags.empty()) {
764  /* List all tags */
765  std::string buf;
766  for (auto &tag : this->selected->tags) {
767  if (!buf.empty()) buf += ", ";
768  buf += tag;
769  }
770  SetDParamStr(0, buf);
771  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TAGS);
772  }
773 
774  if (this->selected->IsSelected()) {
775  /* When selected show all manually selected content that depends on this */
776  ConstContentVector tree;
778 
779  std::string buf;
780  for (const ContentInfo *ci : tree) {
781  if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
782 
783  if (!buf.empty()) buf += ", ";
784  buf += ci->name;
785  }
786  if (!buf.empty()) {
787  SetDParamStr(0, buf);
788  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
789  }
790  }
791  }
792 
793  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
794  {
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;
797 
798  ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
799  return;
800  }
801 
802  switch (widget) {
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
806 
807  this->selected = *it;
808  this->list_pos = it - this->content.begin();
809 
810  const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
811  if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
813  this->content.ForceResort();
814  }
815 
816  if (this->filter_data.types.any()) {
817  this->content.ForceRebuild();
818  }
819 
820  this->InvalidateData();
821  break;
822  }
823 
824  case WID_NCL_CHECKBOX:
825  case WID_NCL_TYPE:
826  case WID_NCL_NAME:
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;
830  } else {
831  this->content.SetSortType(widget - WID_NCL_CHECKBOX);
832  this->content.ForceResort();
833  this->SortContentList();
834  }
835  this->ScrollToSelected();
836  this->InvalidateData();
837  break;
838 
839  case WID_NCL_SELECT_ALL:
841  this->InvalidateData();
842  break;
843 
846  this->InvalidateData();
847  break;
848 
849  case WID_NCL_UNSELECT:
851  this->InvalidateData();
852  break;
853 
854  case WID_NCL_CANCEL:
855  this->Close();
856  break;
857 
858  case WID_NCL_OPEN_URL:
859  if (this->selected != nullptr) {
860  OpenBrowser(this->selected->url);
861  }
862  break;
863 
864  case WID_NCL_DOWNLOAD:
866  break;
867 
870  this->OpenExternalSearch();
871  } else {
872  ShowQuery(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION, STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER, this, ExternalSearchDisclaimerCallback);
873  }
874  break;
875  }
876  }
877 
878  EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
879  {
880  if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == ES_NOT_HANDLED) {
881  switch (keycode) {
882  case WKC_SPACE:
883  case WKC_RETURN:
884  if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
885  if (this->selected != nullptr) {
887  this->content.ForceResort();
888  this->InvalidateData();
889  }
890  if (this->filter_data.types.any()) {
891  this->content.ForceRebuild();
892  this->InvalidateData();
893  }
894  return ES_HANDLED;
895  }
896  /* space is pressed and filter is focused. */
897  [[fallthrough]];
898 
899  default:
900  return ES_NOT_HANDLED;
901  }
902  }
903 
904  if (this->content.empty()) {
905  if (this->UpdateFilterState()) {
906  this->content.ForceRebuild();
907  this->InvalidateData();
908  }
909  return ES_HANDLED;
910  }
911 
912  this->selected = this->content[this->list_pos];
913 
914  if (this->UpdateFilterState()) {
915  this->content.ForceRebuild();
916  } else {
917  /* Scroll to the new content if it is outside the current range. */
918  this->ScrollToSelected();
919  }
920 
921  /* redraw window */
922  this->InvalidateData();
923  return ES_HANDLED;
924  }
925 
926  void OnEditboxChanged(WidgetID wid) override
927  {
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();
933  }
934  }
935 
936  void OnResize() override
937  {
938  this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
939  }
940 
941  void OnReceiveContentInfo(const ContentInfo *rci) override
942  {
943  if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci);
944  this->content.ForceRebuild();
945  this->InvalidateData(0, false);
946  }
947 
948  void OnDownloadComplete(ContentID) override
949  {
950  this->content.ForceResort();
951  this->InvalidateData();
952  }
953 
954  void OnConnect(bool success) override
955  {
956  if (!success) {
957  ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
958  this->Close();
959  return;
960  }
961 
962  this->InvalidateData();
963  }
964 
970  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
971  {
972  if (!gui_scope) return;
973  if (this->content.NeedRebuild()) this->BuildContentList();
974 
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) {
980  switch (ci->state) {
983  this->filesize_sum += ci->filesize;
984  break;
985 
987  show_select_all = true;
988  show_select_upgrade |= ci->upgrade;
989  break;
990 
991  default:
992  break;
993  }
994  }
995 
996  /* If data == 2 then the status window caused this OnInvalidate */
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());
1004  }
1005 
1006  this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
1007  }
1008 };
1009 
1012 
1014  &StateSorter,
1015  &TypeSorter,
1016  &NameSorter,
1017 };
1018 
1020  &TagNameFilter,
1021  &TypeOrSelectedFilter,
1022 };
1023 
1025 
1030 {
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);
1033  }
1034 }
1035 
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),
1042  EndContainer(),
1043  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_BACKGROUND),
1045  /* Top */
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),
1050  EndContainer(),
1051  /* Lists and info. */
1053  /* Left side. */
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),
1063  EndContainer(),
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),
1065  EndContainer(),
1066  NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NCL_SCROLLBAR),
1067  EndContainer(),
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),
1074  EndContainer(),
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),
1077  EndContainer(),
1078  EndContainer(),
1079  /* Right side. */
1081  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_DETAILS), SetResize(1, 1), SetFill(1, 1),
1082  EndContainer(),
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),
1087  EndContainer(),
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),
1091  EndContainer(),
1092  EndContainer(),
1093  EndContainer(),
1094  EndContainer(),
1095  /* Bottom. */
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),
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),
1104  EndContainer(),
1105  EndContainer(),
1106  EndContainer(),
1107  /* Resize button. */
1109  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1110  NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
1111  EndContainer(),
1112  EndContainer(),
1113 };
1114 
1116 static WindowDesc _network_content_list_desc(__FILE__, __LINE__,
1117  WDP_CENTER, "list_content", 630, 460,
1119  0,
1121 );
1122 
1131 {
1132 #if defined(WITH_ZLIB)
1133  std::bitset<CONTENT_TYPE_END> types;
1135  if (cv == nullptr) {
1136  assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
1137  assert(type1 == CONTENT_TYPE_END || type1 != type2);
1140 
1141  if (type1 != CONTENT_TYPE_END) types[type1] = true;
1142  if (type2 != CONTENT_TYPE_END) types[type2] = true;
1143  } else {
1145  }
1146 
1148  new NetworkContentListWindow(&_network_content_list_desc, cv != nullptr, types);
1149 #else
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;
1154  }
1155 #endif /* WITH_ZLIB */
1156 }
WID_NCL_CANCEL
@ WID_NCL_CANCEL
'Cancel' button.
Definition: network_content_widget.h:43
ContentTextfileWindow::ci
const ContentInfo * ci
View the textfile of this ContentInfo.
Definition: network_content_gui.cpp:42
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
ContentInfo::IsSelected
bool IsSelected() const
Is the state either selected or autoselected?
Definition: tcp_content.cpp:27
NetworkContentListWindow::NameSorter
static bool NameSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by name.
Definition: network_content_gui.cpp:433
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:144
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
WID_NCL_SELECT_ALL
@ WID_NCL_SELECT_ALL
'Select all' button.
Definition: network_content_widget.h:39
ContentCallback
Callbacks for notifying others about incoming data.
Definition: network_content.h:29
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
ContentInfo::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
Definition: tcp_content.cpp:54
PC_DARK_BLUE
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
Definition: palette_func.h:75
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:88
ContentInfo::name
std::string name
Name of the content.
Definition: tcp_content_type.h:67
ContentInfo::type
ContentType type
Type of content.
Definition: tcp_content_type.h:63
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
ClientNetworkContentSocketHandler::End
ConstContentIterator End() const
Get the end of the content inf iterator.
Definition: network_content.h:141
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:212
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Definition: misc_gui.cpp:1227
SetDParamMaxDigits
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:143
WID_NCL_TYPE
@ WID_NCL_TYPE
'Type' button.
Definition: network_content_widget.h:30
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
NetworkContentListWindow::StateSorter
static bool StateSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by state.
Definition: network_content_gui.cpp:450
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
NetworkContentDownloadStatusWindow::NetworkContentDownloadStatusWindow
NetworkContentDownloadStatusWindow()
Create a new download window based on a list of content information with flags whether to download th...
Definition: network_content_gui.cpp:200
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:327
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
CONTENT_TYPE_GAME_LIBRARY
@ CONTENT_TYPE_GAME_LIBRARY
The content consists of a GS library.
Definition: tcp_content_type.h:29
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
ContentInfo::upgrade
bool upgrade
This item is an upgrade.
Definition: tcp_content_type.h:76
ContentInfo::DOES_NOT_EXIST
@ DOES_NOT_EXIST
The content does not exist in the content system.
Definition: tcp_content_type.h:59
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
NetworkContentListWindow::OpenExternalSearch
void OpenExternalSearch()
Search external websites for content.
Definition: network_content_gui.cpp:353
ScanScenarios
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition: fios.cpp:716
WID_NCL_NAME
@ WID_NCL_NAME
'Name' button.
Definition: network_content_widget.h:31
Filtering::state
bool state
Filter on/off.
Definition: sortlist_type.h:36
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:821
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
ContentInfo::filesize
uint32_t filesize
Size of the file.
Definition: tcp_content_type.h:65
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition: fileio.cpp:427
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1130
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GUIList< const ContentInfo *, std::nullptr_t, ContentListFilterData & >
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NetworkContentListWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_content_gui.cpp:970
NetworkContentListWindow::GUIContentList
GUIList< const ContentInfo *, std::nullptr_t, ContentListFilterData & > GUIContentList
List with content infos.
Definition: network_content_gui.cpp:331
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:42
NetworkContentListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: network_content_gui.cpp:936
NetworkContentDownloadStatusWindow::receivedTypes
std::vector< ContentType > receivedTypes
Types we received so we can update their cache.
Definition: network_content_gui.cpp:193
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
CONTENT_TYPE_NEWGRF
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
Definition: tcp_content_type.h:21
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
ContentVector
std::vector< ContentInfo * > ContentVector
Vector with content info.
Definition: network_content.h:19
ContentListFilterData::types
std::bitset< CONTENT_TYPE_END > types
Content types displayed.
Definition: network_content_gui.cpp:319
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
Window::IsWidgetFocused
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition: window_gui.h:420
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
WID_NCL_UNSELECT
@ WID_NCL_UNSELECT
'Unselect all' button.
Definition: network_content_widget.h:41
ContentInfo::url
std::string url
URL related to the content.
Definition: tcp_content_type.h:69
RequestNewGRFScan
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition: openttd.cpp:1546
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:124
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2334
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:585
WID_NCL_TEXTFILE
@ WID_NCL_TEXTFILE
Open readme, changelog (+1) or license (+2) of a file in the content window.
Definition: network_content_widget.h:37
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
BaseNetworkContentDownloadStatusWindow
Base window for showing the download status of content.
Definition: network_content_gui.h:18
BaseNetworkContentDownloadStatusWindow::downloaded_files
uint downloaded_files
Number of files downloaded.
Definition: network_content_gui.h:23
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
NetworkContentListWindow::EDITBOX_MAX_SIZE
static const uint EDITBOX_MAX_SIZE
Maximum size of the editbox in characters.
Definition: network_content_gui.cpp:333
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:28
CONTENT_TYPE_END
@ CONTENT_TYPE_END
Helper to mark the end of the types.
Definition: tcp_content_type.h:30
ContentInfo::version
std::string version
Version of the content.
Definition: tcp_content_type.h:68
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:344
ClientNetworkContentSocketHandler::Clear
void Clear()
Clear all downloaded content information.
Definition: network_content.cpp:1066
WID_NCDS_PROGRESS_TEXT
@ WID_NCDS_PROGRESS_TEXT
Text explaining what is happening.
Definition: network_content_widget.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
ContentInfo::md5sum
MD5Hash md5sum
The MD5 checksum.
Definition: tcp_content_type.h:72
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:22
TFT_CHANGELOG
@ TFT_CHANGELOG
Content changelog.
Definition: textfile_type.h:18
ConstContentIterator
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
Definition: network_content.h:26
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
WID_NCL_FILTER
@ WID_NCL_FILTER
Filter editbox.
Definition: network_content_widget.h:27
WID_NCL_MATRIX
@ WID_NCL_MATRIX
Panel with list of content.
Definition: network_content_widget.h:33
NetworkContentListWindow::checkbox_size
Dimension checkbox_size
Size of checkbox/"blot" sprite.
Definition: network_content_gui.cpp:343
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
ContentType
ContentType
The values in the enum are important; they are used as database 'keys'.
Definition: tcp_content_type.h:18
NetworkContentListWindow::NetworkContentListWindow
NetworkContentListWindow(WindowDesc *desc, bool select_all, const std::bitset< CONTENT_TYPE_END > &types)
Create the content list window.
Definition: network_content_gui.cpp:544
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
WN_NETWORK_WINDOW_CONTENT_LIST
@ WN_NETWORK_WINDOW_CONTENT_LIST
Network content list.
Definition: window_type.h:36
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
GetContentInfoSubDir
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
Definition: tcp_content.cpp:186
NetworkContentListWindow::DrawMatrix
void DrawMatrix(const Rect &r) const
Draw/fill the matrix with the list of content to download.
Definition: network_content_gui.cpp:644
find_index
int find_index(Container const &container, typename Container::const_reference item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: container_func.hpp:41
NetworkContentListWindow::TagNameFilter
static bool CDECL TagNameFilter(const ContentInfo *const *a, ContentListFilterData &filter)
Filter content by tags/name.
Definition: network_content_gui.cpp:467
NetworkContentListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: network_content_gui.cpp:581
WID_NCL_BACKGROUND
@ WID_NCL_BACKGROUND
Resize button.
Definition: network_content_widget.h:24
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:26
BaseNetworkContentDownloadStatusWindow::cur_id
uint32_t cur_id
The current ID of the downloaded file.
Definition: network_content_gui.h:25
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
ClientNetworkContentSocketHandler::RequestContentList
void RequestContentList(ContentType type)
Request the content list for the given type.
Definition: network_content.cpp:189
NetworkContentListWindow::UpdateFilterState
bool UpdateFilterState()
Update filter state based on current window state.
Definition: network_content_gui.cpp:515
include
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
Definition: container_func.hpp:24
Scrollbar::UpdateListPositionOnKeyPress
EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition: widget.cpp:2281
NetworkContentListWindow::BuildContentTypeStringList
friend void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
Definition: network_content_gui.cpp:1029
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1188
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content_type.h:28
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
GUIList::GetFiltering
Filtering GetFiltering() const
Export current filter conditions.
Definition: sortlist_type.h:188
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
ContentInfo::UNSELECTED
@ UNSELECTED
The content has not been selected.
Definition: tcp_content_type.h:55
NetworkContentListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: network_content_gui.cpp:348
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:343
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GUIList::SortFunction
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
Definition: sortlist_type.h:49
BaseNetworkContentDownloadStatusWindow::total_files
uint total_files
Number of files to download.
Definition: network_content_gui.h:22
BaseNetworkContentDownloadStatusWindow::total_bytes
uint total_bytes
Number of bytes to download.
Definition: network_content_gui.h:20
ClientNetworkContentSocketHandler::UnselectAll
void UnselectAll()
Unselect everything that we've not downloaded so far.
Definition: network_content.cpp:912
NetworkContentListWindow::content
GUIContentList content
List with content.
Definition: network_content_gui.cpp:339
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:52
NetworkContentListWindow::ScrollToSelected
void ScrollToSelected()
Make sure that the currently selected content info is within the visible part of the matrix.
Definition: network_content_gui.cpp:526
_accepted_external_search
static bool _accepted_external_search
Whether the user accepted to enter external websites during this session.
Definition: network_content_gui.cpp:37
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
ShowNetworkContentListWindow
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentType type2)
Show the content list window with a given set of content.
Definition: network_content_gui.cpp:1130
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:254
CONTENT_FILTER_TEXT
@ CONTENT_FILTER_TEXT
Filter by query sting.
Definition: network_content_gui.cpp:324
NetworkContentListWindow::SortContentList
void SortContentList()
Sort the content list.
Definition: network_content_gui.cpp:458
WID_NCL_FILTER_CAPT
@ WID_NCL_FILTER_CAPT
Caption for the filter editbox.
Definition: network_content_widget.h:26
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
Filtering
Data structure describing what to show in the list (filter criteria).
Definition: sortlist_type.h:35
ContentListFilterData::string_filter
StringFilter string_filter
Text filter of content list.
Definition: network_content_gui.cpp:318
WID_NCL_DETAILS
@ WID_NCL_DETAILS
Panel with content details.
Definition: network_content_widget.h:36
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:765
NetworkContentListWindow::filter_data
ContentListFilterData filter_data
Filter for content list.
Definition: network_content_gui.cpp:341
BuildContentTypeStringList
void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
Definition: network_content_gui.cpp:1029
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:244
ContentInfo::SELECTED
@ SELECTED
The content has been manually selected.
Definition: tcp_content_type.h:56
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1007
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:198
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
_nested_network_content_list_widgets
static constexpr NWidgetPart _nested_network_content_list_widgets[]
The widgets for the content list.
Definition: network_content_gui.cpp:1037
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:845
ClientNetworkContentSocketHandler::RemoveCallback
void RemoveCallback(ContentCallback *cb)
Remove a callback.
Definition: network_content.h:148
ContentInfo::tags
StringList tags
Tags associated with the content.
Definition: tcp_content_type.h:74
ClientNetworkContentSocketHandler::DownloadSelectedContent
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
Definition: network_content.cpp:309
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
NetworkContentListWindow::TypeOrSelectedFilter
static bool CDECL TypeOrSelectedFilter(const ContentInfo *const *a, ContentListFilterData &filter)
Filter content by type, but still show content selected for download.
Definition: network_content_gui.cpp:477
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
_nested_network_content_download_status_window_widgets
static constexpr NWidgetPart _nested_network_content_download_status_window_widgets[]
Nested widgets for the download window.
Definition: network_content_gui.cpp:85
TFT_README
@ TFT_README
Content readme.
Definition: textfile_type.h:17
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3140
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
NetworkContentDownloadStatusWindow
Window for showing the download status of content.
Definition: network_content_gui.cpp:191
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
TarScanner::NONE
@ NONE
Scan nothing.
Definition: fileio_func.h:64
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
ContentInfo::dependencies
std::vector< ContentID > dependencies
The dependencies (unique server side ids)
Definition: tcp_content_type.h:73
WID_NCDS_CANCELOK
@ WID_NCDS_CANCELOK
(Optional) Cancel/OK button.
Definition: network_content_widget.h:19
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
WID_NCL_DOWNLOAD
@ WID_NCL_DOWNLOAD
'Download' button.
Definition: network_content_widget.h:44
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition: tcp_content_type.h:22
_network_content_client
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Definition: network_content.cpp:35
TFT_LICENSE
@ TFT_LICENSE
Content license.
Definition: textfile_type.h:19
NetworkContentListWindow::ExternalSearchDisclaimerCallback
static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
Callback function for disclaimer about entering external websites.
Definition: network_content_gui.cpp:395
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
BaseNetworkContentDownloadStatusWindow::name
std::string name
The current name of the downloaded file.
Definition: network_content_gui.h:26
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:775
CONTENT_TYPE_BASE_GRAPHICS
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
Definition: tcp_content_type.h:20
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
TarScanner::SCENARIO
@ SCENARIO
Scan for scenarios and heightmaps.
Definition: fileio_func.h:68
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
WID_NCL_SCROLLBAR
@ WID_NCL_SCROLLBAR
Scrollbar of matrix.
Definition: network_content_widget.h:34
ContentInfo::ALREADY_HERE
@ ALREADY_HERE
The content is already at the client side.
Definition: tcp_content_type.h:58
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
WID_NCL_OPEN_URL
@ WID_NCL_OPEN_URL
'Open url' button.
Definition: network_content_widget.h:42
ContentListFilterData
Filter data for NetworkContentListWindow.
Definition: network_content_gui.cpp:317
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1220
NetworkContentListWindow::list_pos
int list_pos
Our position in the list.
Definition: network_content_gui.cpp:346
WID_NCL_SELECT_UPDATE
@ WID_NCL_SELECT_UPDATE
'Select updates' button.
Definition: network_content_widget.h:40
ClientNetworkContentSocketHandler::ReverseLookupTreeDependency
void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const
Reverse lookup the dependencies of all parents over a given child.
Definition: network_content.cpp:956
ContentInfo::AUTOSELECTED
@ AUTOSELECTED
The content has been selected as dependency.
Definition: tcp_content_type.h:57
CONTENT_TYPE_AI_LIBRARY
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
Definition: tcp_content_type.h:23
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
ClientNetworkContentSocketHandler::ToggleSelectedState
void ToggleSelectedState(const ContentInfo *ci)
Toggle the state of a content info and check its dependencies.
Definition: network_content.cpp:920
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:472
WID_NCL_SEL_ALL_UPDATE
@ WID_NCL_SEL_ALL_UPDATE
NWID_SELECTION widget for select all/update buttons..
Definition: network_content_widget.h:46
NetworkContentListWindow::last_sorting
static Listing last_sorting
The last sorting setting.
Definition: network_content_gui.cpp:335
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:485
ContentID
ContentID
Unique identifier for the content.
Definition: tcp_content_type.h:47
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
ContentInfo::filename
std::string filename
Filename (for the .tar.gz; only valid on download)
Definition: tcp_content_type.h:66
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
network_content_gui.h
NetworkContentListWindow::auto_select
bool auto_select
Automatically select all content when the meta-data becomes available.
Definition: network_content_gui.cpp:340
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
NetworkContentListWindow::filesize_sum
uint filesize_sum
The sum of all selected file sizes.
Definition: network_content_gui.cpp:347
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
EventState
EventState
State of handling an event.
Definition: window_type.h:738
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition: base_media_base.h:198
CONTENT_TYPE_BEGIN
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
Definition: tcp_content_type.h:19
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:57
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
NetworkContentListWindow::TypeSorter
static bool TypeSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by type.
Definition: network_content_gui.cpp:439
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
BaseNetworkContentDownloadStatusWindow::downloaded_bytes
uint downloaded_bytes
Number of bytes downloaded.
Definition: network_content_gui.h:21
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
ClientNetworkContentSocketHandler::AddCallback
void AddCallback(ContentCallback *cb)
Add a callback to this class.
Definition: network_content.h:146
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
ContentInfo::state
State state
Whether the content info is selected (for download)
Definition: tcp_content_type.h:75
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:366
CONTENT_TYPE_BASE_SOUNDS
@ CONTENT_TYPE_BASE_SOUNDS
The content consists of base sounds.
Definition: tcp_content_type.h:26
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
NetworkContentListWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: network_content_gui.cpp:342
BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow
BaseNetworkContentDownloadStatusWindow(WindowDesc *desc)
Create the window with the given description.
Definition: network_content_gui.cpp:104
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
NetworkContentListWindow::DrawDetails
void DrawDetails(const Rect &r) const
Helper function to draw the details part of this window.
Definition: network_content_gui.cpp:688
WID_NCL_CHECKBOX
@ WID_NCL_CHECKBOX
Button above checkboxes.
Definition: network_content_widget.h:29
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:295
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
GUIList< const ContentInfo *, std::nullptr_t, ContentListFilterData & >::FilterFunction
bool CDECL FilterFunction(const const ContentInfo * *, ContentListFilterData &)
Signature of filter function.
Definition: sortlist_type.h:50
ClientNetworkContentSocketHandler::SelectAll
void SelectAll()
Select everything we can select.
Definition: network_content.cpp:890
TarScanner::BASESET
@ BASESET
Scan for base sets.
Definition: fileio_func.h:65
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
CONTENT_FILTER_TYPE_OR_SELECTED
@ CONTENT_FILTER_TYPE_OR_SELECTED
Filter by being of displayed type or selected for download.
Definition: network_content_gui.cpp:325
NetworkContentListWindow
Window that lists the content that's at the content server.
Definition: network_content_gui.cpp:329
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
NetworkContentListWindow::BuildContentList
void BuildContentList()
(Re)build the network game list as its amount has changed because an item has been added or deleted f...
Definition: network_content_gui.cpp:407
CONTENT_TYPE_SCENARIO
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
Definition: tcp_content_type.h:24
_network_content_list_desc
static WindowDesc _network_content_list_desc(__FILE__, __LINE__, WDP_CENTER, "list_content", 630, 460, WC_NETWORK_WINDOW, WC_NONE, 0, std::begin(_nested_network_content_list_widgets), std::end(_nested_network_content_list_widgets))
Window description of the content list.
NetworkContentListWindow::content_type_strs
static std::string content_type_strs[CONTENT_TYPE_END]
Cached strings for all content types.
Definition: network_content_gui.cpp:350
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
Window
Data structure for an opened window.
Definition: window_gui.h:267
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
NetworkContentListWindow::selected
const ContentInfo * selected
The selected content info.
Definition: network_content_gui.cpp:345
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
ClientNetworkContentSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
Disconnect from the content server.
Definition: network_content.cpp:800
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
ClientNetworkContentSocketHandler::SelectUpgrade
void SelectUpgrade()
Select everything that's an update for something we've got.
Definition: network_content.cpp:901
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
ContentInfo::id
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content_type.h:64
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:323
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
TarScanner::Mode
Mode
The mode of tar scanning.
Definition: fileio_func.h:63
WID_NCL_SEARCH_EXTERNAL
@ WID_NCL_SEARCH_EXTERNAL
Search external sites for missing NewGRF.
Definition: network_content_widget.h:47
ContentInfo::description
std::string description
Description of the content.
Definition: tcp_content_type.h:70
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
CONTENT_TYPE_HEIGHTMAP
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Definition: tcp_content_type.h:25
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:233
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:187
ConstContentVector
std::vector< const ContentInfo * > ConstContentVector
Vector with constant content info.
Definition: network_content.h:21
NetworkContentListWindow::FilterContentList
void FilterContentList()
Filter the content list.
Definition: network_content_gui.cpp:485
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
_network_content_download_status_window_desc
static WindowDesc _network_content_download_status_window_desc(__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WDF_MODAL, std::begin(_nested_network_content_download_status_window_widgets), std::end(_nested_network_content_download_status_window_widgets))
Window description for the download window.
NetworkContentListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: network_content_gui.cpp:623
GUIList::SetFiltering
void SetFiltering(Filtering f)
Import filter conditions.
Definition: sortlist_type.h:202
WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
@ WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
Network content download status.
Definition: window_type.h:40
WID_NCDS_PROGRESS_BAR
@ WID_NCDS_PROGRESS_BAR
Simple progress bar.
Definition: network_content_widget.h:17
ContentInfo::unique_id
uint32_t unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content_type.h:71
GUIList::SetFilterType
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
Definition: sortlist_type.h:176
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
NetworkContentListWindow::sorter_funcs
static GUIContentList::SortFunction *const sorter_funcs[]
Sorter functions.
Definition: network_content_gui.cpp:337
ContentTextfileWindow
Window for displaying the textfile of an item in the content list.
Definition: network_content_gui.cpp:41
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27
NetworkContentListWindow::filter_funcs
static GUIContentList::FilterFunction *const filter_funcs[]
Filter functions.
Definition: network_content_gui.cpp:338
ClientNetworkContentSocketHandler::Begin
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
Definition: network_content.h:137
CONTENT_TYPE_BASE_MUSIC
@ CONTENT_TYPE_BASE_MUSIC
The content consists of base music.
Definition: tcp_content_type.h:27
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:151
NetworkContentListWindow::last_filtering
static Filtering last_filtering
The last filtering setting.
Definition: network_content_gui.cpp:336
ContentListFilterCriteria
ContentListFilterCriteria
Filter criteria for NetworkContentListWindow.
Definition: network_content_gui.cpp:323