OpenTTD Source  13.2.1
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 "network_content_gui.h"
25 
26 
27 #include "table/strings.h"
28 #include "../table/sprites.h"
29 
30 #include <bitset>
31 
32 #include "../safeguards.h"
33 
34 
36 static bool _accepted_external_search = false;
37 
38 
41  const ContentInfo *ci;
42 
44  {
45  const char *textfile = this->ci->GetTextfile(file_type);
46  this->LoadTextfile(textfile, GetContentInfoSubDir(this->ci->type));
47  }
48 
49  StringID GetTypeString() const
50  {
51  switch (this->ci->type) {
52  case CONTENT_TYPE_NEWGRF: return STR_CONTENT_TYPE_NEWGRF;
53  case CONTENT_TYPE_BASE_GRAPHICS: return STR_CONTENT_TYPE_BASE_GRAPHICS;
54  case CONTENT_TYPE_BASE_SOUNDS: return STR_CONTENT_TYPE_BASE_SOUNDS;
55  case CONTENT_TYPE_BASE_MUSIC: return STR_CONTENT_TYPE_BASE_MUSIC;
56  case CONTENT_TYPE_AI: return STR_CONTENT_TYPE_AI;
57  case CONTENT_TYPE_AI_LIBRARY: return STR_CONTENT_TYPE_AI_LIBRARY;
58  case CONTENT_TYPE_GAME: return STR_CONTENT_TYPE_GAME_SCRIPT;
59  case CONTENT_TYPE_GAME_LIBRARY: return STR_CONTENT_TYPE_GS_LIBRARY;
60  case CONTENT_TYPE_SCENARIO: return STR_CONTENT_TYPE_SCENARIO;
61  case CONTENT_TYPE_HEIGHTMAP: return STR_CONTENT_TYPE_HEIGHTMAP;
62  default: NOT_REACHED();
63  }
64  }
65 
66  void SetStringParameters(int widget) const override
67  {
68  if (widget == WID_TF_CAPTION) {
69  SetDParam(0, this->GetTypeString());
70  SetDParamStr(1, this->ci->name);
71  }
72  }
73 };
74 
75 void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci)
76 {
77  CloseWindowById(WC_TEXTFILE, file_type);
78  new ContentTextfileWindow(file_type, ci);
79 }
80 
83  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
84  NWidget(WWT_PANEL, COLOUR_GREY),
86  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_BAR), SetFill(1, 0),
87  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(350, 0),
88  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCDS_CANCELOK), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), SetFill(1, 0),
89  EndContainer(),
90  EndContainer(),
91 };
92 
95  WDP_CENTER, nullptr, 0, 0,
97  WDF_MODAL,
99 );
100 
102  Window(desc), cur_id(UINT32_MAX)
103 {
106 
108 }
109 
111 {
113  this->Window::Close();
114 }
115 
117 {
118  switch (widget) {
120  SetDParamMaxDigits(0, 8);
121  SetDParamMaxDigits(1, 8);
122  SetDParamMaxDigits(2, 8);
123  *size = GetStringBoundingBox(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE);
124  /* We need some spacing for the 'border' */
127  break;
128 
131  break;
132  }
133 }
134 
136 {
137  switch (widget) {
138  case WID_NCDS_PROGRESS_BAR: {
139  /* Draw the % complete with a bar and a text */
140  DrawFrameRect(r, COLOUR_GREY, FR_BORDERONLY | FR_LOWERED);
141  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
142  DrawFrameRect(ir.WithWidth((uint64)ir.Width() * this->downloaded_bytes / this->total_bytes, false), COLOUR_MAUVE, FR_NONE);
143  SetDParam(0, this->downloaded_bytes);
144  SetDParam(1, this->total_bytes);
145  SetDParam(2, this->downloaded_bytes * 100LL / this->total_bytes);
146  DrawString(ir.left, ir.right, CenterBounds(ir.top, ir.bottom, FONT_HEIGHT_NORMAL), STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, TC_FROMSTRING, SA_HOR_CENTER);
147  break;
148  }
149 
150  case WID_NCDS_PROGRESS_TEXT: {
151  StringID str;
152  if (this->downloaded_bytes == this->total_bytes) {
153  str = STR_CONTENT_DOWNLOAD_COMPLETE;
154  } else if (!this->name.empty()) {
155  SetDParamStr(0, this->name);
156  SetDParam(1, this->downloaded_files);
157  SetDParam(2, this->total_files);
158  str = STR_CONTENT_DOWNLOAD_FILE;
159  } else {
160  str = STR_CONTENT_DOWNLOAD_INITIALISE;
161  }
162  DrawStringMultiLine(r, str, TC_FROMSTRING, SA_CENTER);
163  break;
164  }
165  }
166 }
167 
169 {
170  if (ci->id != this->cur_id) {
171  this->name = ci->filename;
172  this->cur_id = ci->id;
173  this->downloaded_files++;
174  }
175 
176  this->downloaded_bytes += bytes;
177  this->SetDirty();
178 }
179 
180 
183 private:
184  std::vector<ContentType> receivedTypes;
185 
186 public:
192  {
194  }
195 
196  void Close() override
197  {
199  for (auto ctype : this->receivedTypes) {
200  switch (ctype) {
201  case CONTENT_TYPE_AI:
203  /* AI::Rescan calls the scanner. */
204  break;
205  case CONTENT_TYPE_GAME:
207  /* Game::Rescan calls the scanner. */
208  break;
209 
213  mode |= TarScanner::BASESET;
214  break;
215 
216  case CONTENT_TYPE_NEWGRF:
217  /* ScanNewGRFFiles calls the scanner. */
218  break;
219 
222  mode |= TarScanner::SCENARIO;
223  break;
224 
225  default:
226  break;
227  }
228  }
229 
230  TarScanner::DoScan(mode);
231 
232  /* Tell all the backends about what we've downloaded */
233  for (auto ctype : this->receivedTypes) {
234  switch (ctype) {
235  case CONTENT_TYPE_AI:
237  AI::Rescan();
238  break;
239 
240  case CONTENT_TYPE_GAME:
242  Game::Rescan();
243  break;
244 
248  break;
249 
253  break;
254 
258  break;
259 
260  case CONTENT_TYPE_NEWGRF:
262  break;
263 
266  extern void ScanScenarios();
267  ScanScenarios();
269  break;
270 
271  default:
272  break;
273  }
274  }
275 
276  /* Always invalidate the download window; tell it we are going to be gone */
278 
280  }
281 
282  void OnClick(Point pt, int widget, int click_count) override
283  {
284  if (widget == WID_NCDS_CANCELOK) {
285  if (this->downloaded_bytes != this->total_bytes) {
287  this->Close();
288  } else {
289  /* If downloading succeeded, close the online content window. This will close
290  * the current window as well. */
292  }
293  }
294  }
295 
296  void OnDownloadProgress(const ContentInfo *ci, int bytes) override
297  {
299  include(this->receivedTypes, ci->type);
300 
301  /* When downloading is finished change cancel in ok */
302  if (this->downloaded_bytes == this->total_bytes) {
303  this->GetWidget<NWidgetCore>(WID_NCDS_CANCELOK)->widget_data = STR_BUTTON_OK;
304  }
305  }
306 };
307 
311  std::bitset<CONTENT_TYPE_END> types;
312 };
313 
318 };
319 
324 
325  static const uint EDITBOX_MAX_SIZE = 50;
326 
332  bool auto_select;
336 
338  int list_pos;
341 
343 
346  {
347  extern void OpenBrowser(const char *url);
348 
349  char url[1024];
350  const char *last = lastof(url);
351 
352  char *pos = strecpy(url, "https://grfsearch.openttd.org/?", last);
353 
354  if (this->auto_select) {
355  pos = strecpy(pos, "do=searchgrfid&q=", last);
356 
357  bool first = true;
358  for (const ContentInfo *ci : this->content) {
359  if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
360 
361  if (!first) pos = strecpy(pos, ",", last);
362  first = false;
363 
364  pos += seprintf(pos, last, "%08X", ci->unique_id);
365  pos = strecpy(pos, ":", last);
366  pos = md5sumToString(pos, last, ci->md5sum);
367  }
368  } else {
369  pos = strecpy(pos, "do=searchtext&q=", last);
370 
371  /* Escape search term */
372  for (const char *search = this->filter_editbox.text.buf; *search != '\0'; search++) {
373  /* Remove quotes */
374  if (*search == '\'' || *search == '"') continue;
375 
376  /* Escape special chars, such as &%,= */
377  if (*search < 0x30) {
378  pos += seprintf(pos, last, "%%%02X", *search);
379  } else if (pos < last) {
380  *pos = *search;
381  *++pos = '\0';
382  }
383  }
384  }
385 
386  OpenBrowser(url);
387  }
388 
392  static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
393  {
394  if (accepted) {
396  ((NetworkContentListWindow*)w)->OpenExternalSearch();
397  }
398  }
399 
405  {
406  if (!this->content.NeedRebuild()) return;
407 
408  /* Create temporary array of games to use for listing */
409  this->content.clear();
410 
411  bool all_available = true;
412 
414  if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false;
415  this->content.push_back(*iter);
416  }
417 
418  this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
419 
420  this->FilterContentList();
421  this->content.shrink_to_fit();
422  this->content.RebuildDone();
423  this->SortContentList();
424 
425  this->vscroll->SetCount((int)this->content.size()); // Update the scrollbar
426  this->ScrollToSelected();
427  }
428 
430  static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
431  {
432  return strnatcmp(a->name.c_str(), b->name.c_str(), true) < 0; // Sort by name (natural sorting).
433  }
434 
436  static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
437  {
438  int r = 0;
439  if (a->type != b->type) {
441  }
442  if (r == 0) return NameSorter(a, b);
443  return r < 0;
444  }
445 
447  static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
448  {
449  int r = a->state - b->state;
450  if (r == 0) return TypeSorter(a, b);
451  return r < 0;
452  }
453 
456  {
457  if (!this->content.Sort()) return;
458 
459  int idx = find_index(this->content, this->selected);
460  if (idx >= 0) this->list_pos = idx;
461  }
462 
464  static bool CDECL TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
465  {
466  filter.string_filter.ResetState();
467  for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag.c_str());
468 
469  filter.string_filter.AddLine((*a)->name.c_str());
470  return filter.string_filter.GetState();
471  }
472 
474  static bool CDECL TypeOrSelectedFilter(const ContentInfo * const *a, ContentListFilterData &filter)
475  {
476  if (filter.types.none()) return true;
477  if (filter.types[(*a)->type]) return true;
478  return ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED);
479  }
480 
483  {
484  /* Apply filters. */
485  bool changed = false;
486  if (!this->filter_data.string_filter.IsEmpty()) {
487  this->content.SetFilterType(CONTENT_FILTER_TEXT);
488  changed |= this->content.Filter(this->filter_data);
489  }
490  if (this->filter_data.types.any()) {
492  changed |= this->content.Filter(this->filter_data);
493  }
494  if (!changed) return;
495 
496  /* update list position */
497  int idx = find_index(this->content, this->selected);
498  if (idx >= 0) {
499  this->list_pos = idx;
500  return;
501  }
502 
503  /* previously selected item not in list anymore */
504  this->selected = nullptr;
505  this->list_pos = 0;
506  }
507 
513  {
514  Filtering old_params = this->content.GetFiltering();
515  bool new_state = !this->filter_data.string_filter.IsEmpty() || this->filter_data.types.any();
516  if (new_state != old_params.state) {
517  this->content.SetFilterState(new_state);
518  }
519  return new_state != old_params.state;
520  }
521 
524  {
525  if (this->selected == nullptr) return;
526 
527  this->vscroll->ScrollTowards(this->list_pos);
528  }
529 
530  friend void BuildContentTypeStringList();
531 public:
541  NetworkContentListWindow(WindowDesc *desc, bool select_all, const std::bitset<CONTENT_TYPE_END> &types) :
542  Window(desc),
543  auto_select(select_all),
545  selected(nullptr),
546  list_pos(0)
547  {
548  this->CreateNestedTree();
549  this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
551 
552  this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
553 
555  this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
557  this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
558  this->filter_data.types = types;
559 
561  this->content.SetListing(this->last_sorting);
562  this->content.SetFiltering(this->last_filtering);
563  this->content.SetSortFuncs(this->sorter_funcs);
564  this->content.SetFilterFuncs(this->filter_funcs);
565  this->UpdateFilterState();
566  this->content.ForceRebuild();
567  this->FilterContentList();
568  this->SortContentList();
569  this->InvalidateData();
570  }
571 
572  void Close() override
573  {
575  this->Window::Close();
576  }
577 
578  void OnInit() override
579  {
580  this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT));
581  }
582 
583  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
584  {
585  switch (widget) {
586  case WID_NCL_CHECKBOX:
587  size->width = this->checkbox_size.width + padding.width;
588  break;
589 
590  case WID_NCL_TYPE: {
591  Dimension d = *size;
592  for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
593  d = maxdim(d, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS));
594  }
595  size->width = d.width + padding.width;
596  break;
597  }
598 
599  case WID_NCL_MATRIX:
600  resize->height = std::max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL) + padding.height;
601  size->height = 10 * resize->height;
602  break;
603  }
604  }
605 
606 
607  void DrawWidget(const Rect &r, int widget) const override
608  {
609  switch (widget) {
610  case WID_NCL_DETAILS:
611  this->DrawDetails(r);
612  break;
613 
614  case WID_NCL_MATRIX:
615  this->DrawMatrix(r);
616  break;
617  }
618  }
619 
620  void OnPaint() override
621  {
622  const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
623 
624  if (this->content.NeedRebuild()) {
625  this->BuildContentList();
626  }
627 
628  this->DrawWidgets();
629 
630  switch (this->content.SortType()) {
632  case WID_NCL_TYPE - WID_NCL_CHECKBOX: this->DrawSortButtonState(WID_NCL_TYPE, arrow); break;
633  case WID_NCL_NAME - WID_NCL_CHECKBOX: this->DrawSortButtonState(WID_NCL_NAME, arrow); break;
634  }
635  }
636 
641  void DrawMatrix(const Rect &r) const
642  {
643  Rect checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX)->GetCurrentRect();
644  Rect name = this->GetWidget<NWidgetBase>(WID_NCL_NAME)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
645  Rect type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE)->GetCurrentRect();
646 
647  /* Fill the matrix with the information */
648  int sprite_y_offset = (this->resize.step_height - this->checkbox_size.height) / 2;
649  int text_y_offset = (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2;
650 
651  Rect mr = r.WithHeight(this->resize.step_height);
652  auto iter = this->content.begin() + this->vscroll->GetPosition();
653  size_t last = this->vscroll->GetPosition() + this->vscroll->GetCapacity();
654  auto end = (last < this->content.size()) ? this->content.begin() + last : this->content.end();
655 
656  for (; iter != end; iter++) {
657  const ContentInfo *ci = *iter;
658 
659  if (ci == this->selected) GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), PC_GREY);
660 
661  SpriteID sprite;
662  SpriteID pal = PAL_NONE;
663  switch (ci->state) {
664  case ContentInfo::UNSELECTED: sprite = SPR_BOX_EMPTY; break;
665  case ContentInfo::SELECTED: sprite = SPR_BOX_CHECKED; break;
666  case ContentInfo::AUTOSELECTED: sprite = SPR_BOX_CHECKED; break;
667  case ContentInfo::ALREADY_HERE: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
668  case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
669  default: NOT_REACHED();
670  }
671  DrawSprite(sprite, pal, checkbox.left + (sprite == SPR_BLOT ? 3 : 2), mr.top + sprite_y_offset + (sprite == SPR_BLOT ? 0 : 1));
672 
673  StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
674  DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER);
675 
676  DrawString(name.left, name.right, mr.top + text_y_offset, ci->name, TC_BLACK);
677  mr = mr.Translate(0, this->resize.step_height);
678  }
679  }
680 
685  void DrawDetails(const Rect &r) const
686  {
687  /* Height for the title banner */
689 
690  Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.frametext);
691  Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
692  tr.top += HEADER_HEIGHT;
693 
694  /* Create the nice grayish rectangle at the details top */
696  DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
697 
698  /* Draw the total download size */
699  SetDParam(0, this->filesize_sum);
700  DrawString(tr.left, tr.right, tr.bottom - FONT_HEIGHT_NORMAL + 1, STR_CONTENT_TOTAL_DOWNLOAD_SIZE);
701 
702  if (this->selected == nullptr) return;
703 
704  /* And fill the rest of the details when there's information to place there */
705  DrawStringMultiLine(hr.left, hr.right, hr.top + FONT_HEIGHT_NORMAL, hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
706 
707  /* Also show the total download size, so keep some space from the bottom */
709 
710  if (this->selected->upgrade) {
711  SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
712  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_UPDATE);
714  }
715 
716  SetDParamStr(0, this->selected->name);
717  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_NAME);
718 
719  if (!this->selected->version.empty()) {
720  SetDParamStr(0, this->selected->version);
721  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_VERSION);
722  }
723 
724  if (!this->selected->description.empty()) {
725  SetDParamStr(0, this->selected->description);
726  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DESCRIPTION);
727  }
728 
729  if (!this->selected->url.empty()) {
730  SetDParamStr(0, this->selected->url);
731  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_URL);
732  }
733 
734  SetDParam(0, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS);
735  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TYPE);
736 
738  SetDParam(0, this->selected->filesize);
739  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_FILESIZE);
740 
741  if (!this->selected->dependencies.empty()) {
742  /* List dependencies */
743  char buf[DRAW_STRING_BUFFER] = "";
744  char *p = buf;
745  for (auto &cid : this->selected->dependencies) {
746  /* Try to find the dependency */
748  for (; iter != _network_content_client.End(); iter++) {
749  const ContentInfo *ci = *iter;
750  if (ci->id != cid) continue;
751 
752  p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", (*iter)->name.c_str());
753  break;
754  }
755  }
756  SetDParamStr(0, buf);
757  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DEPENDENCIES);
758  }
759 
760  if (!this->selected->tags.empty()) {
761  /* List all tags */
762  char buf[DRAW_STRING_BUFFER] = "";
763  char *p = buf;
764  for (auto &tag : this->selected->tags) {
765  p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", tag.c_str());
766  }
767  SetDParamStr(0, buf);
768  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TAGS);
769  }
770 
771  if (this->selected->IsSelected()) {
772  /* When selected show all manually selected content that depends on this */
773  ConstContentVector tree;
775 
776  char buf[DRAW_STRING_BUFFER] = "";
777  char *p = buf;
778  for (const ContentInfo *ci : tree) {
779  if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
780 
781  p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name.c_str());
782  }
783  if (p != buf) {
784  SetDParamStr(0, buf);
785  tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
786  }
787  }
788  }
789 
790  void OnClick(Point pt, int widget, int click_count) override
791  {
792  if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_END) {
793  if (this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE) return;
794 
795  ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
796  return;
797  }
798 
799  switch (widget) {
800  case WID_NCL_MATRIX: {
801  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX);
802  if (id_v >= this->content.size()) return; // click out of bounds
803 
804  this->selected = this->content[id_v];
805  this->list_pos = id_v;
806 
807  const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
808  if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
810  this->content.ForceResort();
811  }
812 
813  if (this->filter_data.types.any()) {
814  this->content.ForceRebuild();
815  }
816 
817  this->InvalidateData();
818  break;
819  }
820 
821  case WID_NCL_CHECKBOX:
822  case WID_NCL_TYPE:
823  case WID_NCL_NAME:
824  if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
825  this->content.ToggleSortOrder();
826  if (this->content.size() > 0) this->list_pos = (int)this->content.size() - this->list_pos - 1;
827  } else {
828  this->content.SetSortType(widget - WID_NCL_CHECKBOX);
829  this->content.ForceResort();
830  this->SortContentList();
831  }
832  this->ScrollToSelected();
833  this->InvalidateData();
834  break;
835 
836  case WID_NCL_SELECT_ALL:
838  this->InvalidateData();
839  break;
840 
843  this->InvalidateData();
844  break;
845 
846  case WID_NCL_UNSELECT:
848  this->InvalidateData();
849  break;
850 
851  case WID_NCL_CANCEL:
852  this->Close();
853  break;
854 
855  case WID_NCL_OPEN_URL:
856  if (this->selected != nullptr) {
857  extern void OpenBrowser(const char *url);
858  OpenBrowser(this->selected->url.c_str());
859  }
860  break;
861 
862  case WID_NCL_DOWNLOAD:
864  break;
865 
868  this->OpenExternalSearch();
869  } else {
870  ShowQuery(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION, STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER, this, ExternalSearchDisclaimerCallback);
871  }
872  break;
873  }
874  }
875 
876  EventState OnKeyPress(WChar key, uint16 keycode) override
877  {
878  if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == ES_NOT_HANDLED) {
879  switch (keycode) {
880  case WKC_SPACE:
881  case WKC_RETURN:
882  if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
883  if (this->selected != nullptr) {
885  this->content.ForceResort();
886  this->InvalidateData();
887  }
888  if (this->filter_data.types.any()) {
889  this->content.ForceRebuild();
890  this->InvalidateData();
891  }
892  return ES_HANDLED;
893  }
894  /* space is pressed and filter is focused. */
895  FALLTHROUGH;
896 
897  default:
898  return ES_NOT_HANDLED;
899  }
900  }
901 
902  if (this->content.size() == 0) {
903  if (this->UpdateFilterState()) {
904  this->content.ForceRebuild();
905  this->InvalidateData();
906  }
907  return ES_HANDLED;
908  }
909 
910  this->selected = this->content[this->list_pos];
911 
912  if (this->UpdateFilterState()) {
913  this->content.ForceRebuild();
914  } else {
915  /* Scroll to the new content if it is outside the current range. */
916  this->ScrollToSelected();
917  }
918 
919  /* redraw window */
920  this->InvalidateData();
921  return ES_HANDLED;
922  }
923 
924  void OnEditboxChanged(int wid) override
925  {
926  if (wid == WID_NCL_FILTER) {
927  this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.buf);
928  this->UpdateFilterState();
929  this->content.ForceRebuild();
930  this->InvalidateData();
931  }
932  }
933 
934  void OnResize() override
935  {
936  this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
937  }
938 
939  void OnReceiveContentInfo(const ContentInfo *rci) override
940  {
941  if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci);
942  this->content.ForceRebuild();
943  this->InvalidateData(0, false);
944  }
945 
946  void OnDownloadComplete(ContentID cid) override
947  {
948  this->content.ForceResort();
949  this->InvalidateData();
950  }
951 
952  void OnConnect(bool success) override
953  {
954  if (!success) {
955  ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
956  this->Close();
957  return;
958  }
959 
960  this->InvalidateData();
961  }
962 
968  void OnInvalidateData(int data = 0, bool gui_scope = true) override
969  {
970  if (!gui_scope) return;
971  if (this->content.NeedRebuild()) this->BuildContentList();
972 
973  /* To sum all the bytes we intend to download */
974  this->filesize_sum = 0;
975  bool show_select_all = false;
976  bool show_select_upgrade = false;
977  for (const ContentInfo *ci : this->content) {
978  switch (ci->state) {
981  this->filesize_sum += ci->filesize;
982  break;
983 
985  show_select_all = true;
986  show_select_upgrade |= ci->upgrade;
987  break;
988 
989  default:
990  break;
991  }
992  }
993 
994  /* If data == 2 then the status window caused this OnInvalidate */
996  this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
997  this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
998  this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
999  this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
1000  for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
1001  this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == nullptr);
1002  }
1003 
1004  this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
1005  }
1006 };
1007 
1010 
1012  &StateSorter,
1013  &TypeSorter,
1014  &NameSorter,
1015 };
1016 
1018  &TagNameFilter,
1019  &TypeOrSelectedFilter,
1020 };
1021 
1023 
1028 {
1029  for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
1031  }
1032 }
1033 
1037  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
1038  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_CONTENT_TITLE, STR_NULL),
1039  NWidget(WWT_DEFSIZEBOX, COLOUR_LIGHT_BLUE),
1040  EndContainer(),
1041  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_BACKGROUND),
1044  /* Top */
1045  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),
1046  NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NCL_FILTER), SetFill(1, 0), SetResize(1, 0),
1047  SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1048  EndContainer(),
1051  /* Left side. */
1052  NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
1056  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CHECKBOX), SetMinimalSize(13, 1), SetDataTip(STR_EMPTY, STR_NULL),
1057  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TYPE),
1058  SetDataTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
1059  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_NAME), SetResize(1, 0), SetFill(1, 0),
1060  SetDataTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
1061  EndContainer(),
1062  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),
1063  EndContainer(),
1064  NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NCL_SCROLLBAR),
1065  EndContainer(),
1067  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NCL_SEL_ALL_UPDATE), SetResize(1, 0), SetFill(1, 0),
1068  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_UPDATE), SetResize(1, 0), SetFill(1, 0),
1069  SetDataTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
1070  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_ALL), SetResize(1, 0), SetFill(1, 0),
1071  SetDataTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
1072  EndContainer(),
1073  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_UNSELECT), SetResize(1, 0), SetFill(1, 0),
1074  SetDataTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
1075  EndContainer(),
1076  EndContainer(),
1077  /* Right side. */
1078  NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
1079  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_DETAILS), SetResize(1, 1), SetFill(1, 1), EndContainer(),
1081  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
1082  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
1083  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_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
1087  EndContainer(),
1088  EndContainer(),
1089  EndContainer(),
1091  /* Bottom. */
1093  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SEARCH_EXTERNAL), SetResize(1, 0), SetFill(1, 0),
1094  SetDataTip(STR_CONTENT_SEARCH_EXTERNAL, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP),
1096  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CANCEL), SetResize(1, 0), SetFill(1, 0),
1097  SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
1098  NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
1099  SetDataTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
1100  EndContainer(),
1101  EndContainer(),
1103  /* Resize button. */
1105  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1106  NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE),
1107  EndContainer(),
1108  EndContainer(),
1109 };
1110 
1113  WDP_CENTER, "list_content", 630, 460,
1115  0,
1117 );
1118 
1127 {
1128 #if defined(WITH_ZLIB)
1129  std::bitset<CONTENT_TYPE_END> types;
1131  if (cv == nullptr) {
1132  assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
1133  assert(type1 == CONTENT_TYPE_END || type1 != type2);
1136 
1137  if (type1 != CONTENT_TYPE_END) types[type1] = true;
1138  if (type2 != CONTENT_TYPE_END) types[type2] = true;
1139  } else {
1141  }
1142 
1144  new NetworkContentListWindow(&_network_content_list_desc, cv != nullptr, types);
1145 #else
1146  ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
1147  /* Connection failed... clean up the mess */
1148  if (cv != nullptr) {
1149  for (ContentInfo *ci : *cv) delete ci;
1150  }
1151 #endif /* WITH_ZLIB */
1152 }
WID_NCL_NAME
@ WID_NCL_NAME
'Name' button.
Definition: network_content_widget.h:31
ContentTextfileWindow::ci
const ContentInfo * ci
View the textfile of this ContentInfo.
Definition: network_content_gui.cpp:41
NetworkContentDownloadStatusWindow::OnDownloadProgress
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
We have progress in the download of a file.
Definition: network_content_gui.cpp:296
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
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:430
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:137
NetworkContentListWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: network_content_gui.cpp:924
ContentCallback
Callbacks for notifying others about incoming data.
Definition: network_content.h:28
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:3254
WID_NCL_DETAILS
@ WID_NCL_DETAILS
Panel with content details.
Definition: network_content_widget.h:36
ContentInfo::name
std::string name
Name of the content.
Definition: tcp_content_type.h:65
NetworkContentListWindow::OnConnect
void OnConnect(bool success) override
Callback for when the connection has finished.
Definition: network_content_gui.cpp:952
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:338
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
ContentInfo::GetTextfile
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
Definition: tcp_content.cpp:54
ContentInfo::type
ContentType type
Type of content.
Definition: tcp_content_type.h:61
WID_NCL_MATRIX
@ WID_NCL_MATRIX
Panel with list of content.
Definition: network_content_widget.h:33
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3156
ClientNetworkContentSocketHandler::End
ConstContentIterator End() const
Get the end of the content inf iterator.
Definition: network_content.h:138
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:158
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:669
NetworkContentListWindow::StateSorter
static bool StateSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by state.
Definition: network_content_gui.cpp:447
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:890
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
NetworkContentListWindow::GUIContentList
GUIList< const ContentInfo *, ContentListFilterData & > GUIContentList
List with content infos.
Definition: network_content_gui.cpp:323
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:191
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
CONTENT_TYPE_GAME_LIBRARY
@ CONTENT_TYPE_GAME_LIBRARY
The content consists of a GS library.
Definition: tcp_content_type.h:27
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
ContentInfo::upgrade
bool upgrade
This item is an upgrade.
Definition: tcp_content_type.h:74
_network_content_download_status_window_desc
static WindowDesc _network_content_download_status_window_desc(WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WDF_MODAL, _nested_network_content_download_status_window_widgets, lengthof(_nested_network_content_download_status_window_widgets))
Window description for the download window.
ContentInfo::DOES_NOT_EXIST
@ DOES_NOT_EXIST
The content does not exist in the content system.
Definition: tcp_content_type.h:57
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
GUIList::SetFilterType
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
Definition: sortlist_type.h:155
NetworkContentListWindow::OpenExternalSearch
void OpenExternalSearch()
Search external websites for content.
Definition: network_content_gui.cpp:345
ScanScenarios
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition: fios.cpp:745
NetworkContentListWindow::OnDownloadComplete
void OnDownloadComplete(ContentID cid) override
We have finished downloading a file.
Definition: network_content_gui.cpp:946
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:780
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition: fileio.cpp:410
GUIList< const ContentInfo *, ContentListFilterData & >
BaseNetworkContentDownloadStatusWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_content_gui.cpp:135
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
ContentTextfileWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: network_content_gui.cpp:66
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
NetworkContentListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: network_content_gui.cpp:934
NetworkContentDownloadStatusWindow::receivedTypes
std::vector< ContentType > receivedTypes
Types we received so we can update their cache.
Definition: network_content_gui.cpp:184
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
CONTENT_TYPE_NEWGRF
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
Definition: tcp_content_type.h:19
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1161
ContentVector
std::vector< ContentInfo * > ContentVector
Vector with content info.
Definition: network_content.h:18
ContentListFilterData::types
std::bitset< CONTENT_TYPE_END > types
Content types displayed.
Definition: network_content_gui.cpp:311
include
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
Definition: smallvec_type.hpp:27
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
ContentInfo::url
std::string url
URL related to the content.
Definition: tcp_content_type.h:67
RequestNewGRFScan
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition: openttd.cpp:1453
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
WID_NCL_SCROLLBAR
@ WID_NCL_SCROLLBAR
Scrollbar of matrix.
Definition: network_content_widget.h:34
BaseNetworkContentDownloadStatusWindow::cur_id
uint32 cur_id
The current ID of the downloaded file.
Definition: network_content_gui.h:25
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
NetworkContentListWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: network_content_gui.cpp:876
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
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:104
NetworkContentListWindow::EDITBOX_MAX_SIZE
static const uint EDITBOX_MAX_SIZE
Maximum size of the editbox in characters.
Definition: network_content_gui.cpp:325
NetworkContentListWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: network_content_gui.cpp:572
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:34
CONTENT_TYPE_END
@ CONTENT_TYPE_END
Helper to mark the end of the types.
Definition: tcp_content_type.h:28
ContentInfo::version
std::string version
Version of the content.
Definition: tcp_content_type.h:66
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
ClientNetworkContentSocketHandler::Clear
void Clear()
Clear all downloaded content information.
Definition: network_content.cpp:1067
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2353
NetworkContentListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: network_content_gui.cpp:607
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:30
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF changelog.
Definition: textfile_type.h:18
ConstContentIterator
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
Definition: network_content.h:25
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NetworkContentListWindow::checkbox_size
Dimension checkbox_size
Size of checkbox/"blot" sprite.
Definition: network_content_gui.cpp:335
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
ContentType
ContentType
The values in the enum are important; they are used as database 'keys'.
Definition: tcp_content_type.h:16
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
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:541
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
_nested_network_content_list_widgets
static const NWidgetPart _nested_network_content_list_widgets[]
The widgets for the content list.
Definition: network_content_gui.cpp:1035
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
WN_NETWORK_WINDOW_CONTENT_LIST
@ WN_NETWORK_WINDOW_CONTENT_LIST
Network content list.
Definition: window_type.h:29
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:257
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:789
GetContentInfoSubDir
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
Definition: tcp_content.cpp:187
NetworkContentListWindow::DrawMatrix
void DrawMatrix(const Rect &r) const
Draw/fill the matrix with the list of content to download.
Definition: network_content_gui.cpp:641
NetworkContentListWindow::TagNameFilter
static bool CDECL TagNameFilter(const ContentInfo *const *a, ContentListFilterData &filter)
Filter content by tags/name.
Definition: network_content_gui.cpp:464
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NetworkContentListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: network_content_gui.cpp:578
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:19
WindowDesc
High level window description.
Definition: window_gui.h:102
ClientNetworkContentSocketHandler::RequestContentList
void RequestContentList(ContentType type)
Request the content list for the given type.
Definition: network_content.cpp:190
NetworkContentListWindow::UpdateFilterState
bool UpdateFilterState()
Update filter state based on current window state.
Definition: network_content_gui.cpp:512
NetworkContentListWindow::BuildContentTypeStringList
friend void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
Definition: network_content_gui.cpp:1027
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content_type.h:26
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
ContentInfo::UNSELECTED
@ UNSELECTED
The content has not been selected.
Definition: tcp_content_type.h:53
DRAW_STRING_BUFFER
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
Definition: gfx_func.h:86
NetworkContentListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: network_content_gui.cpp:340
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
WID_NCL_UNSELECT
@ WID_NCL_UNSELECT
'Unselect all' button.
Definition: network_content_widget.h:41
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
NetworkContentListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: network_content_gui.cpp:968
GUIList< const ContentInfo *, ContentListFilterData & >::SortFunction
bool SortFunction(const const ContentInfo * &, const const ContentInfo * &)
Signature of sort function.
Definition: sortlist_type.h:48
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
BaseNetworkContentDownloadStatusWindow::total_files
uint total_files
Number of files to download.
Definition: network_content_gui.h:22
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
WID_NCL_DOWNLOAD
@ WID_NCL_DOWNLOAD
'Download' button.
Definition: network_content_widget.h:44
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:913
NetworkContentListWindow::content
GUIContentList content
List with content.
Definition: network_content_gui.cpp:331
NetworkContentListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_content_gui.cpp:790
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content_type.h:50
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:523
IsInsideBS
static 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:214
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
_accepted_external_search
static bool _accepted_external_search
Whether the user accepted to enter external websites during this session.
Definition: network_content_gui.cpp:36
find_index
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: smallvec_type.hpp:44
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
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:1126
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
CONTENT_FILTER_TEXT
@ CONTENT_FILTER_TEXT
Filter by query sting.
Definition: network_content_gui.cpp:316
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1129
NetworkContentListWindow::SortContentList
void SortContentList()
Sort the content list.
Definition: network_content_gui.cpp:455
ContentInfo::md5sum
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content_type.h:70
Scrollbar::UpdateListPositionOnKeyPress
EventState UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition: widget.cpp:2374
Filtering
Data structure describing what to show in the list (filter criteria).
Definition: sortlist_type.h:35
WID_NCL_CHECKBOX
@ WID_NCL_CHECKBOX
Button above checkboxes.
Definition: network_content_widget.h:29
ContentListFilterData::string_filter
StringFilter string_filter
Text filter of content list.
Definition: network_content_gui.cpp:310
NetworkContentListWindow::filter_data
ContentListFilterData filter_data
Filter for content list.
Definition: network_content_gui.cpp:333
BuildContentTypeStringList
void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
Definition: network_content_gui.cpp:1027
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:266
WID_NCL_BACKGROUND
@ WID_NCL_BACKGROUND
Resize button.
Definition: network_content_widget.h:24
WID_NCL_FILTER_CAPT
@ WID_NCL_FILTER_CAPT
Caption for the filter editbox.
Definition: network_content_widget.h:26
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
We have progress in the download of a file.
Definition: network_content_gui.cpp:168
WID_NCL_FILTER
@ WID_NCL_FILTER
Filter editbox.
Definition: network_content_widget.h:27
ContentInfo::SELECTED
@ SELECTED
The content has been manually selected.
Definition: tcp_content_type.h:54
WID_NCDS_PROGRESS_BAR
@ WID_NCDS_PROGRESS_BAR
Simple progress bar.
Definition: network_content_widget.h:17
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
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:1058
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:145
WID_NCL_CANCEL
@ WID_NCL_CANCEL
'Cancel' button.
Definition: network_content_widget.h:43
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
_nested_network_content_download_status_window_widgets
static const NWidgetPart _nested_network_content_download_status_window_widgets[]
Nested widgets for the download window.
Definition: network_content_gui.cpp:82
Window::IsWidgetFocused
bool IsWidgetFocused(byte widget_index) const
Check if given widget is focused within this window.
Definition: window_gui.h:361
ClientNetworkContentSocketHandler::RemoveCallback
void RemoveCallback(ContentCallback *cb)
Remove a callback.
Definition: network_content.h:145
ContentInfo::tags
StringList tags
Tags associated with the content.
Definition: tcp_content_type.h:72
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:519
ClientNetworkContentSocketHandler::DownloadSelectedContent
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
Definition: network_content.cpp:310
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:116
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:474
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:154
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
WID_NCL_SEL_ALL_UPDATE
@ WID_NCL_SEL_ALL_UPDATE
NWID_SELECTION widget for select all/update buttons..
Definition: network_content_widget.h:46
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:233
TFT_README
@ TFT_README
NewGRF 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:3194
NetworkContentListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: network_content_gui.cpp:583
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
NetworkContentDownloadStatusWindow
Window for showing the download status of content.
Definition: network_content_gui.cpp:182
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
WID_NCL_SEARCH_EXTERNAL
@ WID_NCL_SEARCH_EXTERNAL
Search external sites for missing NewGRF.
Definition: network_content_widget.h:47
TarScanner::NONE
@ NONE
Scan nothing.
Definition: fileio_func.h:66
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:244
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
ContentInfo::dependencies
std::vector< ContentID > dependencies
The dependencies (unique server side ids)
Definition: tcp_content_type.h:71
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition: tcp_content_type.h:20
_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
NewGRF license.
Definition: textfile_type.h:19
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NetworkContentListWindow::ExternalSearchDisclaimerCallback
static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
Callback function for disclaimer about entering external websites.
Definition: network_content_gui.cpp:392
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1266
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:160
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
CONTENT_TYPE_BASE_GRAPHICS
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
Definition: tcp_content_type.h:18
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
TarScanner::SCENARIO
@ SCENARIO
Scan for scenarios and heightmaps.
Definition: fileio_func.h:70
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
ContentInfo::ALREADY_HERE
@ ALREADY_HERE
The content is already at the client side.
Definition: tcp_content_type.h:56
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
ContentListFilterData
Filter data for NetworkContentListWindow.
Definition: network_content_gui.cpp:309
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
NetworkContentListWindow::list_pos
int list_pos
Our position in the list.
Definition: network_content_gui.cpp:338
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:957
NetworkContentListWindow::OnReceiveContentInfo
void OnReceiveContentInfo(const ContentInfo *rci) override
We received a content info.
Definition: network_content_gui.cpp:939
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
ContentInfo::AUTOSELECTED
@ AUTOSELECTED
The content has been selected as dependency.
Definition: tcp_content_type.h:55
CONTENT_TYPE_AI_LIBRARY
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
Definition: tcp_content_type.h:21
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
PC_DARK_BLUE
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
Definition: gfx_func.h:262
ClientNetworkContentSocketHandler::ToggleSelectedState
void ToggleSelectedState(const ContentInfo *ci)
Toggle the state of a content info and check its dependencies.
Definition: network_content.cpp:921
WC_NETWORK_WINDOW
@ WC_NETWORK_WINDOW
Network window; Window numbers:
Definition: window_type.h:465
BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: network_content_gui.cpp:116
GUIList< const ContentInfo *, ContentListFilterData & >::FilterFunction
bool CDECL FilterFunction(const const ContentInfo * *, ContentListFilterData &)
Signature of filter function.
Definition: sortlist_type.h:49
WID_NCDS_PROGRESS_TEXT
@ WID_NCDS_PROGRESS_TEXT
Text explaining what is happening.
Definition: network_content_widget.h:18
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
NetworkContentListWindow::last_sorting
static Listing last_sorting
The last sorting setting.
Definition: network_content_gui.cpp:327
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:478
ContentID
ContentID
Unique identifier for the content.
Definition: tcp_content_type.h:45
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
_network_content_list_desc
static WindowDesc _network_content_list_desc(WDP_CENTER, "list_content", 630, 460, WC_NETWORK_WINDOW, WC_NONE, 0, _nested_network_content_list_widgets, lengthof(_nested_network_content_list_widgets))
Window description of the content list.
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
ContentInfo::filename
std::string filename
Filename (for the .tar.gz; only valid on download)
Definition: tcp_content_type.h:64
network_content_gui.h
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
NetworkContentListWindow::auto_select
bool auto_select
Automatically select all content when the meta-data becomes available.
Definition: network_content_gui.cpp:332
NetworkContentListWindow::filesize_sum
uint filesize_sum
The sum of all selected file sizes.
Definition: network_content_gui.cpp:339
NetworkContentDownloadStatusWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: network_content_gui.cpp:282
EventState
EventState
State of handling an event.
Definition: window_type.h:719
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition: base_media_base.h:189
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
CONTENT_TYPE_BEGIN
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
Definition: tcp_content_type.h:17
GUIList::SetFiltering
void SetFiltering(Filtering f)
Import filter conditions.
Definition: sortlist_type.h:181
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
NetworkContentListWindow::TypeSorter
static bool TypeSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by type.
Definition: network_content_gui.cpp:436
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
WID_NCDS_CANCELOK
@ WID_NCDS_CANCELOK
(Optional) Cancel/OK button.
Definition: network_content_widget.h:19
BaseNetworkContentDownloadStatusWindow::downloaded_bytes
uint downloaded_bytes
Number of bytes downloaded.
Definition: network_content_gui.h:21
SetAlignment
static NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1064
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
ClientNetworkContentSocketHandler::AddCallback
void AddCallback(ContentCallback *cb)
Add a callback to this class.
Definition: network_content.h:143
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:414
ContentInfo::state
State state
Whether the content info is selected (for download)
Definition: tcp_content_type.h:73
CONTENT_TYPE_BASE_SOUNDS
@ CONTENT_TYPE_BASE_SOUNDS
The content consists of base sounds.
Definition: tcp_content_type.h:24
ContentInfo::unique_id
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content_type.h:69
NetworkContentListWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: network_content_gui.cpp:334
BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow
BaseNetworkContentDownloadStatusWindow(WindowDesc *desc)
Create the window with the given description.
Definition: network_content_gui.cpp:101
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:344
NetworkContentListWindow::DrawDetails
void DrawDetails(const Rect &r) const
Helper function to draw the details part of this window.
Definition: network_content_gui.cpp:685
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
WID_NCL_TYPE
@ WID_NCL_TYPE
'Type' button.
Definition: network_content_widget.h:30
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2427
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1191
ClientNetworkContentSocketHandler::SelectAll
void SelectAll()
Select everything we can select.
Definition: network_content.cpp:891
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
TarScanner::BASESET
@ BASESET
Scan for base sets.
Definition: fileio_func.h:67
BaseNetworkContentDownloadStatusWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: network_content_gui.cpp:110
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:317
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:737
NetworkContentListWindow
Window that lists the content that's at the content server.
Definition: network_content_gui.cpp:321
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
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:404
CONTENT_TYPE_SCENARIO
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
Definition: tcp_content_type.h:22
GUIList::GetFiltering
Filtering GetFiltering() const
Export current filter conditions.
Definition: sortlist_type.h:167
Window
Data structure for an opened window.
Definition: window_gui.h:213
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:572
NetworkContentDownloadStatusWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: network_content_gui.cpp:196
NetworkContentListWindow::selected
const ContentInfo * selected
The selected content info.
Definition: network_content_gui.cpp:337
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
ClientNetworkContentSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
Disconnect from the content server.
Definition: network_content.cpp:802
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:161
ClientNetworkContentSocketHandler::SelectUpgrade
void SelectUpgrade()
Select everything that's an update for something we've got.
Definition: network_content.cpp:902
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
ContentInfo::id
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content_type.h:62
AI::Rescan
static void Rescan()
Rescans all searchpaths for available AIs.
Definition: ai_core.cpp:335
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
WID_NCL_SELECT_UPDATE
@ WID_NCL_SELECT_UPDATE
'Select updates' button.
Definition: network_content_widget.h:40
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1274
TarScanner::Mode
Mode
The mode of tar scanning.
Definition: fileio_func.h:65
ContentInfo::description
std::string description
Description of the content.
Definition: tcp_content_type.h:68
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
CONTENT_TYPE_HEIGHTMAP
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Definition: tcp_content_type.h:23
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
WID_NCL_OPEN_URL
@ WID_NCL_OPEN_URL
'Open url' button.
Definition: network_content_widget.h:42
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
ConstContentVector
std::vector< const ContentInfo * > ConstContentVector
Vector with constant content info.
Definition: network_content.h:20
SetDParamMaxDigits
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:111
NetworkContentListWindow::content_type_strs
static char content_type_strs[CONTENT_TYPE_END][64]
Cached strings for all content types.
Definition: network_content_gui.cpp:342
NetworkContentListWindow::FilterContentList
void FilterContentList()
Filter the content list.
Definition: network_content_gui.cpp:482
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
NetworkContentListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: network_content_gui.cpp:620
WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
@ WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
Network content download status.
Definition: window_type.h:33
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
NetworkContentListWindow::sorter_funcs
static GUIContentList::SortFunction *const sorter_funcs[]
Sorter functions.
Definition: network_content_gui.cpp:329
ContentTextfileWindow
Window for displaying the textfile of an item in the content list.
Definition: network_content_gui.cpp:40
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
ContentInfo::filesize
uint32 filesize
Size of the file.
Definition: tcp_content_type.h:63
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:33
NetworkContentListWindow::filter_funcs
static GUIContentList::FilterFunction *const filter_funcs[]
Filter functions.
Definition: network_content_gui.cpp:330
ClientNetworkContentSocketHandler::Begin
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
Definition: network_content.h:134
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
CONTENT_TYPE_BASE_MUSIC
@ CONTENT_TYPE_BASE_MUSIC
The content consists of base music.
Definition: tcp_content_type.h:25
NetworkContentListWindow::last_filtering
static Filtering last_filtering
The last filtering setting.
Definition: network_content_gui.cpp:328
ContentListFilterCriteria
ContentListFilterCriteria
Filter criteria for NetworkContentListWindow.
Definition: network_content_gui.cpp:315
WID_NCL_SELECT_ALL
@ WID_NCL_SELECT_ALL
'Select all' button.
Definition: network_content_widget.h:39
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:61