OpenTTD Source 15.0-beta2
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 "../base_media_graphics.h"
19#include "../base_media_music.h"
20#include "../base_media_sounds.h"
21#include "../openttd.h"
22#include "../sortlist_type.h"
23#include "../stringfilter_type.h"
24#include "../querystring_gui.h"
25#include "../core/geometry_func.hpp"
26#include "../textfile_gui.h"
27#include "../fios.h"
28#include "network_content_gui.h"
29
30
31#include "table/strings.h"
32#include "../table/sprites.h"
33
34#include <bitset>
35
36#include "../safeguards.h"
37
38
40static bool _accepted_external_search = false;
41
42
45 const ContentInfo *ci = nullptr;
46
48 {
49 this->ConstructWindow();
50
51 auto textfile = this->ci->GetTextfile(file_type);
52 this->LoadTextfile(textfile.value(), GetContentInfoSubDir(this->ci->type));
53 }
54
55 StringID GetTypeString() const
56 {
57 switch (this->ci->type) {
58 case CONTENT_TYPE_NEWGRF: return STR_CONTENT_TYPE_NEWGRF;
59 case CONTENT_TYPE_BASE_GRAPHICS: return STR_CONTENT_TYPE_BASE_GRAPHICS;
60 case CONTENT_TYPE_BASE_SOUNDS: return STR_CONTENT_TYPE_BASE_SOUNDS;
61 case CONTENT_TYPE_BASE_MUSIC: return STR_CONTENT_TYPE_BASE_MUSIC;
62 case CONTENT_TYPE_AI: return STR_CONTENT_TYPE_AI;
63 case CONTENT_TYPE_AI_LIBRARY: return STR_CONTENT_TYPE_AI_LIBRARY;
64 case CONTENT_TYPE_GAME: return STR_CONTENT_TYPE_GAME_SCRIPT;
65 case CONTENT_TYPE_GAME_LIBRARY: return STR_CONTENT_TYPE_GS_LIBRARY;
66 case CONTENT_TYPE_SCENARIO: return STR_CONTENT_TYPE_SCENARIO;
67 case CONTENT_TYPE_HEIGHTMAP: return STR_CONTENT_TYPE_HEIGHTMAP;
68 default: NOT_REACHED();
69 }
70 }
71
72 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
73 {
74 if (widget == WID_TF_CAPTION) {
75 return GetString(stringid, this->GetTypeString(), this->ci->name);
76 }
77
78 return this->Window::GetWidgetString(widget, stringid);
79 }
80};
81
82void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci)
83{
84 CloseWindowById(WC_TEXTFILE, file_type);
85 new ContentTextfileWindow(file_type, ci);
86}
87
90 NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
91 NWidget(WWT_PANEL, COLOUR_GREY),
93 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_BAR), SetFill(1, 0),
94 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(350, 0),
95 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCDS_CANCELOK), SetStringTip(STR_BUTTON_CANCEL), SetFill(1, 0),
98};
99
102 WDP_CENTER, nullptr, 0, 0,
106);
107
115
117{
119 this->Window::Close();
120}
121
122void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize)
123{
124 switch (widget) {
126 auto max_value = GetParamMaxDigits(8);
127 size = GetStringBoundingBox(GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, max_value, max_value, max_value));
128 /* We need some spacing for the 'border' */
131 break;
132 }
133
136 break;
137 }
138}
139
141{
142 switch (widget) {
144 /* Draw the % complete with a bar and a text */
147 DrawFrameRect(ir.WithWidth((uint64_t)ir.Width() * this->downloaded_bytes / this->total_bytes, _current_text_dir == TD_RTL), COLOUR_MAUVE, {});
148 DrawString(ir.left, ir.right, CenterBounds(ir.top, ir.bottom, GetCharacterHeight(FS_NORMAL)),
149 GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, this->downloaded_bytes, this->total_bytes, this->downloaded_bytes * 100LL / this->total_bytes),
150 TC_FROMSTRING, SA_HOR_CENTER);
151 break;
152 }
153
155 if (this->downloaded_bytes == this->total_bytes) {
156 DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_COMPLETE, TC_FROMSTRING, SA_CENTER);
157 } else if (!this->name.empty()) {
159 GetString(STR_CONTENT_DOWNLOAD_FILE, this->name, this->downloaded_files, this->total_files),
160 TC_FROMSTRING, SA_CENTER);
161 } else {
162 DrawStringMultiLine(r, STR_CONTENT_DOWNLOAD_INITIALISE, TC_FROMSTRING, SA_CENTER);
163 }
164 break;
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 /* A negative value means we are resetting; for example, when retrying or using a fallback. */
177 if (bytes < 0) {
178 this->downloaded_bytes = 0;
179 } else {
180 this->downloaded_bytes += bytes;
181 }
182
183 this->SetDirty();
184}
185
186
189private:
190 std::vector<ContentType> receivedTypes{};
191
192public:
201
202 void Close([[maybe_unused]] int data = 0) override
203 {
204 TarScanner::Modes modes{};
205 for (auto ctype : this->receivedTypes) {
206 switch (ctype) {
207 case CONTENT_TYPE_AI:
209 /* AI::Rescan calls the scanner. */
210 break;
213 /* Game::Rescan calls the scanner. */
214 break;
215
220 break;
221
223 /* ScanNewGRFFiles calls the scanner. */
224 break;
225
229 break;
230
231 default:
232 break;
233 }
234 }
235
236 TarScanner::DoScan(modes);
237
238 /* Tell all the backends about what we've downloaded */
239 for (auto ctype : this->receivedTypes) {
240 switch (ctype) {
241 case CONTENT_TYPE_AI:
243 AI::Rescan();
244 break;
245
248 Game::Rescan();
249 break;
250
254 break;
255
259 break;
260
264 break;
265
268 break;
269
274 break;
275
276 default:
277 break;
278 }
279 }
280
281 /* Always invalidate the download window; tell it we are going to be gone */
283
285 }
286
287 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
288 {
289 if (widget == WID_NCDS_CANCELOK) {
290 if (this->downloaded_bytes != this->total_bytes) {
292 this->Close();
293 } else {
294 /* If downloading succeeded, close the online content window. This will close
295 * the current window as well. */
297 }
298 }
299 }
300
301 void OnDownloadProgress(const ContentInfo &ci, int bytes) override
302 {
304 include(this->receivedTypes, ci.type);
305
306 /* When downloading is finished change cancel in ok */
307 if (this->downloaded_bytes == this->total_bytes) {
308 this->GetWidget<NWidgetCore>(WID_NCDS_CANCELOK)->SetString(STR_BUTTON_OK);
309 }
310 }
311};
312
316 std::bitset<CONTENT_TYPE_END> types;
317};
318
324
329
330 static const uint EDITBOX_MAX_SIZE = 50;
331
332 static Listing last_sorting;
334 static const std::initializer_list<GUIContentList::SortFunction * const> sorter_funcs;
335 static const std::initializer_list<GUIContentList::FilterFunction * const> filter_funcs;
337 bool auto_select = false;
341
342 const ContentInfo *selected = nullptr;
343 int list_pos = 0;
344 uint filesize_sum = 0;
345 Scrollbar *vscroll = nullptr;
346
348
351 {
352 std::string url;
353 url.reserve(1024);
354
355 url += "https://grfsearch.openttd.org/?";
356
357 if (this->auto_select) {
358 url += "do=searchgrfid&q=";
359
360 bool first = true;
361 for (const ContentInfo *ci : this->content) {
362 if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
363
364 if (!first) url.push_back(',');
365 first = false;
366
367 fmt::format_to(std::back_inserter(url), "{:08X}:{}", ci->unique_id, FormatArrayAsHex(ci->md5sum));
368 }
369 } else {
370 url += "do=searchtext&q=";
371
372 /* Escape search term */
373 for (const char *search = this->filter_editbox.text.GetText(); *search != '\0'; search++) {
374 /* Remove quotes */
375 if (*search == '\'' || *search == '"') continue;
376
377 /* Escape special chars, such as &%,= */
378 if (*search < 0x30) {
379 fmt::format_to(std::back_inserter(url), "%{:02X}", *search);
380 } else {
381 url.push_back(*search);
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
413 for (const ContentInfo &ci : _network_content_client.Info()) {
414 if (ci.state == ContentInfo::DOES_NOT_EXIST) all_available = false;
415 this->content.push_back(&ci);
416 }
417
418 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
419
420 this->FilterContentList();
421 this->content.RebuildDone();
422 this->SortContentList();
423
424 this->vscroll->SetCount(this->content.size()); // Update the scrollbar
425 this->ScrollToSelected();
426 }
427
429 static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
430 {
431 return StrNaturalCompare(a->name, b->name, true) < 0; // Sort by name (natural sorting).
432 }
433
435 static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
436 {
437 int r = 0;
438 if (a->type != b->type) {
440 }
441 if (r == 0) return NameSorter(a, b);
442 return r < 0;
443 }
444
446 static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
447 {
448 int r = a->state - b->state;
449 if (r == 0) return TypeSorter(a, b);
450 return r < 0;
451 }
452
455 {
456 if (!this->content.Sort()) return;
457
458 int idx = find_index(this->content, this->selected);
459 if (idx >= 0) this->list_pos = idx;
460 }
461
463 static bool TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
464 {
465 if ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED) return true;
466
467 filter.string_filter.ResetState();
468 for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag);
469
470 filter.string_filter.AddLine((*a)->name);
471 return filter.string_filter.GetState();
472 }
473
475 static bool TypeOrSelectedFilter(const ContentInfo * const *a, ContentListFilterData &filter)
476 {
477 if (filter.types.none()) return true;
478 if (filter.types[(*a)->type]) return true;
479 return ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED);
480 }
481
484 {
485 /* Apply filters. */
486 bool changed = false;
487 if (!this->filter_data.string_filter.IsEmpty()) {
489 changed |= this->content.Filter(this->filter_data);
490 }
491 if (this->filter_data.types.any()) {
493 changed |= this->content.Filter(this->filter_data);
494 }
495 if (!changed) return;
496
497 /* update list position */
498 int idx = find_index(this->content, this->selected);
499 if (idx >= 0) {
500 this->list_pos = idx;
501 return;
502 }
503
504 /* previously selected item not in list anymore */
505 this->selected = nullptr;
506 this->list_pos = 0;
507 }
508
514 {
515 Filtering old_params = this->content.GetFiltering();
516 bool new_state = !this->filter_data.string_filter.IsEmpty() || this->filter_data.types.any();
517 if (new_state != old_params.state) {
518 this->content.SetFilterState(new_state);
519 }
520 return new_state != old_params.state;
521 }
522
525 {
526 if (this->selected == nullptr) return;
527
528 this->vscroll->ScrollTowards(this->list_pos);
529 }
530
532public:
542 NetworkContentListWindow(WindowDesc &desc, bool select_all, const std::bitset<CONTENT_TYPE_END> &types) :
543 Window(desc),
544 auto_select(select_all),
546 {
547 this->CreateNestedTree();
548 this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
550
551 this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
552
554 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
556 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
557 this->filter_data.types = types;
558
560 this->content.SetListing(this->last_sorting);
561 this->content.SetFiltering(this->last_filtering);
562 this->content.SetSortFuncs(this->sorter_funcs);
563 this->content.SetFilterFuncs(this->filter_funcs);
564 this->UpdateFilterState();
565 this->content.ForceRebuild();
566 this->FilterContentList();
567 this->SortContentList();
568 this->InvalidateData();
569 }
570
571 void Close([[maybe_unused]] int data = 0) override
572 {
574 this->Window::Close();
575 }
576
577 void OnInit() override
578 {
579 this->checkbox_size = maxdim(maxdim(GetScaledSpriteSize(SPR_BOX_EMPTY), GetScaledSpriteSize(SPR_BOX_CHECKED)), GetScaledSpriteSize(SPR_BLOT));
580 }
581
582 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
583 {
584 switch (widget) {
585 case WID_NCL_CHECKBOX:
586 size.width = this->checkbox_size.width + padding.width;
587 break;
588
589 case WID_NCL_TYPE: {
590 Dimension d = size;
591 for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
592 d = maxdim(d, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS));
593 }
594 size.width = d.width + padding.width;
595 break;
596 }
597
598 case WID_NCL_MATRIX:
599 resize.height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height;
600 size.height = 10 * resize.height;
601 break;
602 }
603 }
604
605
606 void DrawWidget(const Rect &r, WidgetID widget) const override
607 {
608 switch (widget) {
609 case WID_NCL_DETAILS:
610 this->DrawDetails(r);
611 break;
612
613 case WID_NCL_MATRIX:
614 this->DrawMatrix(r);
615 break;
616 }
617 }
618
619 void OnPaint() override
620 {
621 const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
622
623 if (this->content.NeedRebuild()) {
624 this->BuildContentList();
625 }
626
627 this->DrawWidgets();
628
629 switch (this->content.SortType()) {
633 }
634 }
635
640 void DrawMatrix(const Rect &r) const
641 {
642 const Rect checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX)->GetCurrentRect();
643 const Rect name = this->GetWidget<NWidgetBase>(WID_NCL_NAME)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
644 const Rect type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
645
646 /* Fill the matrix with the information */
647 const uint step_height = this->GetWidget<NWidgetBase>(WID_NCL_MATRIX)->resize_y;
648 const int text_y_offset = WidgetDimensions::scaled.matrix.top + (step_height - WidgetDimensions::scaled.matrix.Vertical() - GetCharacterHeight(FS_NORMAL)) / 2;
649
650 Rect mr = r.WithHeight(step_height);
651 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->content);
652 for (auto iter = first; iter != last; iter++) {
653 const ContentInfo *ci = *iter;
654
655 if (ci == this->selected) GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), PC_GREY);
656
657 SpriteID sprite;
658 SpriteID pal = PAL_NONE;
659 switch (ci->state) {
660 case ContentInfo::UNSELECTED: sprite = SPR_BOX_EMPTY; break;
661 case ContentInfo::SELECTED: sprite = SPR_BOX_CHECKED; break;
662 case ContentInfo::AUTOSELECTED: sprite = SPR_BOX_CHECKED; break;
663 case ContentInfo::ALREADY_HERE: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
664 case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
665 default: NOT_REACHED();
666 }
667 DrawSpriteIgnorePadding(sprite, pal, {checkbox.left, mr.top, checkbox.right, mr.bottom}, SA_CENTER);
668
669 StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS;
670 DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER);
671
672 DrawString(name.left, name.right, mr.top + text_y_offset, ci->name, TC_BLACK);
673 mr = mr.Translate(0, step_height);
674 }
675 }
676
681 void DrawDetails(const Rect &r) const
682 {
683 /* Height for the title banner */
685
686 Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.frametext);
687 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
688 tr.top += HEADER_HEIGHT;
689
690 /* Create the nice grayish rectangle at the details top */
692 DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
693
694 /* Draw the total download size */
695 DrawString(tr.left, tr.right, tr.bottom - GetCharacterHeight(FS_NORMAL) + 1, GetString(STR_CONTENT_TOTAL_DOWNLOAD_SIZE, this->filesize_sum));
696
697 if (this->selected == nullptr) return;
698
699 /* And fill the rest of the details when there's information to place there */
700 DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FS_NORMAL), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
701
702 /* Also show the total download size, so keep some space from the bottom */
704
705 if (this->selected->upgrade) {
706 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_UPDATE, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS));
708 }
709
710 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_NAME, this->selected->name));
711
712 if (!this->selected->version.empty()) {
713 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_VERSION, this->selected->version));
714 }
715
716 if (!this->selected->description.empty()) {
717 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_DESCRIPTION, this->selected->description));
718 }
719
720 if (!this->selected->url.empty()) {
721 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_URL, this->selected->url));
722 }
723
724 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_TYPE, STR_CONTENT_TYPE_BASE_GRAPHICS + this->selected->type - CONTENT_TYPE_BASE_GRAPHICS));
725
727 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_FILESIZE, this->selected->filesize));
728
729 std::string_view list_separator = GetListSeparator();
730 if (!this->selected->dependencies.empty()) {
731 /* List dependencies */
732 std::string buf;
733 for (auto &cid : this->selected->dependencies) {
734 /* Try to find the dependency */
735 for (const ContentInfo &ci : _network_content_client.Info()) {
736 if (ci.id != cid) continue;
737
738 if (!buf.empty()) buf += list_separator;
739 buf += ci.name;
740 break;
741 }
742 }
743 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_DEPENDENCIES, std::move(buf)));
744 }
745
746 if (!this->selected->tags.empty()) {
747 /* List all tags */
748 std::string buf;
749 for (auto &tag : this->selected->tags) {
750 if (!buf.empty()) buf += list_separator;
751 buf += tag;
752 }
753 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_TAGS, std::move(buf)));
754 }
755
756 if (this->selected->IsSelected()) {
757 /* When selected show all manually selected content that depends on this */
760
761 std::string buf;
762 for (const ContentInfo *ci : tree) {
763 if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
764
765 if (!buf.empty()) buf += list_separator;
766 buf += ci->name;
767 }
768 if (!buf.empty()) {
769 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF, std::move(buf)));
770 }
771 }
772 }
773
774 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
775 {
776 if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_CONTENT_END) {
777 if (this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE) return;
778
779 ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
780 return;
781 }
782
783 switch (widget) {
784 case WID_NCL_MATRIX: {
785 auto it = this->vscroll->GetScrolledItemFromWidget(this->content, pt.y, this, WID_NCL_MATRIX);
786 if (it == this->content.end()) return; // click out of bounds
787
788 this->selected = *it;
789 this->list_pos = it - this->content.begin();
790
791 const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
792 if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
794 this->content.ForceResort();
795 this->content.ForceRebuild();
796 }
797
798 if (this->filter_data.types.any()) {
799 this->content.ForceRebuild();
800 }
801
802 this->InvalidateData();
803 break;
804 }
805
806 case WID_NCL_CHECKBOX:
807 case WID_NCL_TYPE:
808 case WID_NCL_NAME:
809 if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
810 this->content.ToggleSortOrder();
811 if (!this->content.empty()) this->list_pos = (int)this->content.size() - this->list_pos - 1;
812 } else {
813 this->content.SetSortType(widget - WID_NCL_CHECKBOX);
814 this->content.ForceResort();
815 this->SortContentList();
816 }
817 this->ScrollToSelected();
818 this->InvalidateData();
819 break;
820
823 this->InvalidateData();
824 break;
825
828 this->InvalidateData();
829 break;
830
831 case WID_NCL_UNSELECT:
833 this->InvalidateData();
834 break;
835
836 case WID_NCL_CANCEL:
837 this->Close();
838 break;
839
840 case WID_NCL_OPEN_URL:
841 if (this->selected != nullptr) {
842 OpenBrowser(this->selected->url);
843 }
844 break;
845
846 case WID_NCL_DOWNLOAD:
848 break;
849
852 this->OpenExternalSearch();
853 } else {
854 ShowQuery(
855 GetEncodedString(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION),
856 GetEncodedString(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER),
858 }
859 break;
860 }
861 }
862
863 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
864 {
865 if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == ES_NOT_HANDLED) {
866 switch (keycode) {
867 case WKC_SPACE:
868 case WKC_RETURN:
869 if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
870 if (this->selected != nullptr) {
872 this->content.ForceResort();
873 this->InvalidateData();
874 }
875 if (this->filter_data.types.any()) {
876 this->content.ForceRebuild();
877 this->InvalidateData();
878 }
879 return ES_HANDLED;
880 }
881 /* space is pressed and filter is focused. */
882 [[fallthrough]];
883
884 default:
885 return ES_NOT_HANDLED;
886 }
887 }
888
889 if (this->content.empty()) {
890 if (this->UpdateFilterState()) {
891 this->content.ForceRebuild();
892 this->InvalidateData();
893 }
894 return ES_HANDLED;
895 }
896
897 this->selected = this->content[this->list_pos];
898
899 if (this->UpdateFilterState()) {
900 this->content.ForceRebuild();
901 } else {
902 /* Scroll to the new content if it is outside the current range. */
903 this->ScrollToSelected();
904 }
905
906 /* redraw window */
907 this->InvalidateData();
908 return ES_HANDLED;
909 }
910
911 void OnEditboxChanged(WidgetID wid) override
912 {
913 if (wid == WID_NCL_FILTER) {
914 this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.GetText());
915 this->UpdateFilterState();
916 this->content.ForceRebuild();
917 this->InvalidateData();
918 }
919 }
920
921 void OnResize() override
922 {
923 this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
924 }
925
926 void OnReceiveContentInfo(const ContentInfo &rci) override
927 {
928 if (this->auto_select && !rci.IsSelected()) _network_content_client.ToggleSelectedState(rci);
929 this->content.ForceRebuild();
930 this->InvalidateData(0, false);
931 }
932
934 {
935 this->content.ForceResort();
936 this->InvalidateData();
937 }
938
939 void OnConnect(bool success) override
940 {
941 if (!success) {
942 ShowErrorMessage(GetEncodedString(STR_CONTENT_ERROR_COULD_NOT_CONNECT), {}, WL_ERROR);
943 this->Close();
944 return;
945 }
946
947 this->InvalidateData();
948 }
949
955 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
956 {
957 if (!gui_scope) return;
958 if (this->content.NeedRebuild()) this->BuildContentList();
959
960 /* To sum all the bytes we intend to download */
961 this->filesize_sum = 0;
962 bool show_select_all = false;
963 bool show_select_upgrade = false;
964 for (const ContentInfo *ci : this->content) {
965 switch (ci->state) {
968 this->filesize_sum += ci->filesize;
969 break;
970
972 show_select_all = true;
973 show_select_upgrade |= ci->upgrade;
974 break;
975
976 default:
977 break;
978 }
979 }
980
981 /* If data == 2 then the status window caused this OnInvalidate */
983 this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
984 this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
985 this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade || !this->filter_data.string_filter.IsEmpty());
986 this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
987 for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
988 this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || !this->selected->GetTextfile(tft).has_value());
989 }
990
991 this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->SetString(this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL);
992 }
993};
994
997
998const std::initializer_list<NetworkContentListWindow::GUIContentList::SortFunction * const> NetworkContentListWindow::sorter_funcs = {
999 &StateSorter,
1000 &TypeSorter,
1001 &NameSorter,
1002};
1003
1004const std::initializer_list<NetworkContentListWindow::GUIContentList::FilterFunction * const> NetworkContentListWindow::filter_funcs = {
1005 &TagNameFilter,
1006 &TypeOrSelectedFilter,
1007};
1008
1010
1015{
1016 for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) {
1017 NetworkContentListWindow::content_type_strs[i] = GetString(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS);
1018 }
1019}
1020
1024 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
1025 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetStringTip(STR_CONTENT_TITLE),
1026 NWidget(WWT_DEFSIZEBOX, COLOUR_LIGHT_BLUE),
1027 EndContainer(),
1028 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_BACKGROUND),
1030 /* Top */
1032 NWidget(WWT_TEXT, INVALID_COLOUR, WID_NCL_FILTER_CAPT), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_CONTENT_FILTER_TITLE), SetAlignment(SA_RIGHT | SA_VERT_CENTER),
1033 NWidget(WWT_EDITBOX, COLOUR_LIGHT_BLUE, WID_NCL_FILTER), SetFill(1, 0), SetResize(1, 0),
1034 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1035 EndContainer(),
1036 /* Lists and info. */
1038 /* Left side. */
1043 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CHECKBOX), SetStringTip(STR_EMPTY),
1044 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TYPE),
1045 SetStringTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
1046 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_NAME), SetResize(1, 0), SetFill(1, 0),
1047 SetStringTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
1048 EndContainer(),
1049 NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, WID_NCL_MATRIX), SetResize(1, 1), SetFill(1, 1), SetScrollbar(WID_NCL_SCROLLBAR), SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP),
1050 EndContainer(),
1051 NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NCL_SCROLLBAR),
1052 EndContainer(),
1055 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_UPDATE), SetResize(1, 0), SetFill(1, 0),
1056 SetStringTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
1057 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SELECT_ALL), SetResize(1, 0), SetFill(1, 0),
1058 SetStringTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
1059 EndContainer(),
1060 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_UNSELECT), SetResize(1, 0), SetFill(1, 0),
1061 SetStringTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
1062 EndContainer(),
1063 EndContainer(),
1064 /* Right side. */
1066 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_DETAILS), SetResize(1, 1), SetFill(1, 1),
1067 EndContainer(),
1070 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1071 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1072 EndContainer(),
1074 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1075 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1076 EndContainer(),
1077 EndContainer(),
1078 EndContainer(),
1079 EndContainer(),
1080 /* Bottom. */
1082 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_SEARCH_EXTERNAL), SetResize(1, 0), SetFill(1, 0),
1083 SetStringTip(STR_CONTENT_SEARCH_EXTERNAL, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP),
1085 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CANCEL), SetResize(1, 0), SetFill(1, 0),
1086 SetStringTip(STR_BUTTON_CANCEL),
1087 NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
1088 SetStringTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
1089 EndContainer(),
1090 EndContainer(),
1091 EndContainer(),
1092 /* Resize button. */
1094 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1095 NWidget(WWT_RESIZEBOX, COLOUR_LIGHT_BLUE), SetResizeWidgetTypeTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
1096 EndContainer(),
1097 EndContainer(),
1098};
1099
1102 WDP_CENTER, "list_content", 630, 460,
1104 {},
1106);
1107
1116{
1117#if defined(WITH_ZLIB)
1118 std::bitset<CONTENT_TYPE_END> types;
1120 if (cv == nullptr) {
1121 assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
1122 assert(type1 == CONTENT_TYPE_END || type1 != type2);
1125
1126 if (type1 != CONTENT_TYPE_END) types[type1] = true;
1127 if (type2 != CONTENT_TYPE_END) types[type2] = true;
1128 } else {
1130 }
1131
1133 new NetworkContentListWindow(_network_content_list_desc, cv != nullptr, types);
1134#else
1136 GetEncodedString(STR_CONTENT_NO_ZLIB),
1137 GetEncodedString(STR_CONTENT_NO_ZLIB_SUB),
1138 WL_ERROR);
1139#endif /* WITH_ZLIB */
1140}
static void Rescan()
Rescans all searchpaths for available AIs.
Definition ai_core.cpp:318
constexpr Timpl & Set()
Set all bits.
static uint FindSets()
Do the scan for files.
Base window for showing the download status of content.
uint32_t cur_id
The current ID of the downloaded file.
BaseNetworkContentDownloadStatusWindow(WindowDesc &desc)
Create the window with the given description.
uint downloaded_bytes
Number of bytes downloaded.
uint total_files
Number of files to download.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnDownloadProgress(const ContentInfo &ci, int bytes) override
We have progress in the download of a file.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
std::string name
The current name of the downloaded file.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
uint downloaded_files
Number of files downloaded.
uint total_bytes
Number of bytes to download.
void SelectUpgrade()
Select everything that's an update for something we've got.
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
void RemoveCallback(ContentCallback *cb)
Remove a callback.
void ToggleSelectedState(const ContentInfo &ci)
Toggle the state of a content info and check its dependencies.
void UnselectAll()
Unselect everything that we've not downloaded so far.
void RequestContentList(ContentType type)
Request the content list for the given type.
void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const
Reverse lookup the dependencies of all parents over a given child.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
void Clear()
Clear all downloaded content information.
auto Info() const
Get a read-only view of content info for iterating externally.
void Cancel()
Cancel the current download.
void SelectAll()
Select everything we can select.
Enum-as-bit-set wrapper.
List template of 'things' T to sort in a GUI.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetFiltering(Filtering f)
Import filter conditions.
void SetListing(Listing l)
Import sort conditions.
void SetFilterState(bool state)
Enable or disable the filter.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
Filtering GetFiltering() const
Export current filter conditions.
bool NeedRebuild() const
Check if a rebuild is needed.
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Baseclass for nested widgets.
uint current_x
Current horizontal size (after resizing).
int pos_x
Horizontal position of top-left corner of the widget in the window.
Window that lists the content that's at the content server.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
static bool NameSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by name.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void DrawDetails(const Rect &r) const
Helper function to draw the details part of this window.
void OpenExternalSearch()
Search external websites for content.
void DrawMatrix(const Rect &r) const
Draw/fill the matrix with the list of content to download.
void OnResize() override
Called after the window got resized.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnReceiveContentInfo(const ContentInfo &rci) override
We received a content info.
static std::string content_type_strs[CONTENT_TYPE_END]
Cached strings for all content types.
GUIContentList content
List with content.
uint filesize_sum
The sum of all selected file sizes.
bool auto_select
Automatically select all content when the meta-data becomes available.
ContentListFilterData filter_data
Filter for content list.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static Filtering last_filtering
The last filtering setting.
QueryString filter_editbox
Filter editbox;.
static const std::initializer_list< GUIContentList::SortFunction *const > sorter_funcs
Sorter functions.
static Listing last_sorting
The last sorting setting.
static bool TagNameFilter(const ContentInfo *const *a, ContentListFilterData &filter)
Filter content by tags/name.
int list_pos
Our position in the list.
static bool TypeOrSelectedFilter(const ContentInfo *const *a, ContentListFilterData &filter)
Filter content by type, but still show content selected for download.
const ContentInfo * selected
The selected content info.
void OnInit() override
Notification that the nested widget tree gets initialized.
static const std::initializer_list< GUIContentList::FilterFunction *const > filter_funcs
Filter functions.
static bool TypeSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by type.
void SortContentList()
Sort the content list.
static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
Callback function for disclaimer about entering external websites.
bool UpdateFilterState()
Update filter state based on current window state.
void OnPaint() override
The window must be repainted.
GUIList< const ContentInfo *, std::nullptr_t, ContentListFilterData & > GUIContentList
List with content infos.
static const uint EDITBOX_MAX_SIZE
Maximum size of the editbox in characters.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
void OnDownloadComplete(ContentID) override
We have finished downloading a file.
void BuildContentList()
(Re)build the network game list as its amount has changed because an item has been added or deleted f...
void OnConnect(bool success) override
Callback for when the connection has finished.
NetworkContentListWindow(WindowDesc &desc, bool select_all, const std::bitset< CONTENT_TYPE_END > &types)
Create the content list window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Scrollbar * vscroll
Cache of the vertical scrollbar.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
friend void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
void FilterContentList()
Filter the content list.
Dimension checkbox_size
Size of checkbox/"blot" sprite.
void ScrollToSelected()
Make sure that the currently selected content info is within the visible part of the matrix.
static bool StateSorter(const ContentInfo *const &a, const ContentInfo *const &b)
Sort content by state.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
auto 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.
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:2523
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:2470
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
@ Scenario
Scan for scenarios and heightmaps.
@ Baseset
Scan for base sets.
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition fileio.cpp:374
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
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_...
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
void ScanScenarios()
Force a (re)scan of the scenarios.
Definition fios.cpp:711
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:852
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
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:115
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
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:67
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:245
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:379
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:378
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:387
@ SA_VERT_CENTER
Vertically center the text.
Definition gfx_type.h:383
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
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.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:945
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.
void ShowQuery(EncodedString &&caption, EncodedString &&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...
@ WID_TF_CAPTION
The caption of the window.
Definition misc_widget.h:50
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
std::vector< std::unique_ptr< ContentInfo > > ContentVector
Vector with content info.
std::vector< const ContentInfo * > ConstContentVector
Vector with constant content info.
static bool _accepted_external_search
Whether the user accepted to enter external websites during this session.
static constexpr NWidgetPart _nested_network_content_list_widgets[]
The widgets for the content list.
static WindowDesc _network_content_download_status_window_desc(WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WindowDefaultFlag::Modal, _nested_network_content_download_status_window_widgets)
Window description for the download window.
static constexpr NWidgetPart _nested_network_content_download_status_window_widgets[]
Nested widgets for the download window.
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentType type2)
Show the content list window with a given set of content.
ContentListFilterCriteria
Filter criteria for NetworkContentListWindow.
@ CONTENT_FILTER_TYPE_OR_SELECTED
Filter by being of displayed type or selected for download.
@ CONTENT_FILTER_TEXT
Filter by query string.
static WindowDesc _network_content_list_desc(WDP_CENTER, "list_content", 630, 460, WC_NETWORK_WINDOW, WC_NONE, {}, _nested_network_content_list_widgets)
Window description of the content list.
void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
User interface for downloading files.
@ WID_NCL_CHECKBOX
Button above checkboxes.
@ WID_NCL_NAME
'Name' button.
@ WID_NCL_TYPE
'Type' button.
@ WID_NCL_SEARCH_EXTERNAL
Search external sites for missing NewGRF.
@ WID_NCL_CANCEL
'Cancel' button.
@ WID_NCL_DETAILS
Panel with content details.
@ WID_NCL_SEL_ALL_UPDATE
NWID_SELECTION widget for select all/update buttons..
@ WID_NCL_SELECT_ALL
'Select all' button.
@ WID_NCL_FILTER
Filter editbox.
@ WID_NCL_FILTER_CAPT
Caption for the filter editbox.
@ WID_NCL_DOWNLOAD
'Download' button.
@ WID_NCL_SCROLLBAR
Scrollbar of matrix.
@ WID_NCL_SELECT_UPDATE
'Select updates' button.
@ WID_NCL_TEXTFILE
Open readme, changelog (+1) or license (+2) of a file in the content window.
@ WID_NCL_MATRIX
Panel with list of content.
@ WID_NCL_BACKGROUND
Resize button.
@ WID_NCL_UNSELECT
'Unselect all' button.
@ WID_NCL_OPEN_URL
'Open url' button.
@ WID_NCDS_CANCELOK
(Optional) Cancel/OK button.
@ WID_NCDS_PROGRESS_TEXT
Text explaining what is happening.
@ WID_NCDS_PROGRESS_BAR
Simple progress bar.
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition openttd.cpp:1313
static const uint8_t PC_GREY
Grey palette colour.
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:78
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:514
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:308
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:91
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:57
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:228
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Callbacks for notifying others about incoming data.
Container for all important information about a piece of content.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
uint32_t filesize
Size of the file.
MD5Hash md5sum
The MD5 checksum.
std::string url
URL related to the content.
State state
Whether the content info is selected (for download)
std::string name
Name of the content.
std::string description
Description of the content.
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
std::string version
Version of the content.
ContentID id
Unique (server side) ID for the content.
std::string filename
Filename (for the .tar.gz; only valid on download)
bool IsSelected() const
Is the state either selected or autoselected?
ContentType type
Type of content.
std::vector< ContentID > dependencies
The dependencies (unique server side ids)
@ DOES_NOT_EXIST
The content does not exist in the content system.
@ ALREADY_HERE
The content is already at the client side.
@ AUTOSELECTED
The content has been selected as dependency.
@ UNSELECTED
The content has not been selected.
@ SELECTED
The content has been manually selected.
StringList tags
Tags associated with the content.
bool upgrade
This item is an upgrade.
Filter data for NetworkContentListWindow.
std::bitset< CONTENT_TYPE_END > types
Content types displayed.
StringFilter string_filter
Text filter of content list.
Window for displaying the textfile of an item in the content list.
const ContentInfo * ci
View the textfile of this ContentInfo.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Dimensions (a width and height) of a rectangle in 2D.
Data structure describing what to show in the list (filter criteria).
bool state
Filter on/off.
Data structure describing how to show the list (what sort direction and criteria).
Partial widget specification to allow NWidgets to be written nested.
Window for showing the download status of content.
std::vector< ContentType > receivedTypes
Types we received so we can update their cache.
void OnDownloadProgress(const ContentInfo &ci, int bytes) override
We have progress in the download of a file.
NetworkContentDownloadStatusWindow()
Create a new download window based on a list of content information with flags whether to download th...
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Coordinates of a point in 2D.
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
String filter and state.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
const char * GetText() const
Get the current text.
Definition textbuf.cpp:284
Window for displaying a textfile.
TextfileType file_type
Type of textfile to view.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
High level window description.
Definition window_gui.h:168
Data structure for an opened window.
Definition window_gui.h:274
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1052
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1736
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3164
Window * parent
Parent window.
Definition window_gui.h:329
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:776
ResizeInfo resize
Resize information.
Definition window_gui.h:315
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition window_gui.h:421
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1726
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:485
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1749
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
uint32_t ContentID
Unique identifier for the content.
ContentType
The values in the enum are important; they are used as database 'keys'.
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
@ CONTENT_TYPE_BASE_SOUNDS
The content consists of base sounds.
@ CONTENT_TYPE_GAME_LIBRARY
The content consists of a GS library.
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
@ CONTENT_TYPE_AI
The content consists of an AI.
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
@ CONTENT_TYPE_BASE_MUSIC
The content consists of base music.
@ CONTENT_TYPE_GAME
The content consists of a game script.
@ CONTENT_TYPE_END
Helper to mark the end of the types.
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:296
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:69
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:61
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:49
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:75
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:58
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:55
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:48
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:70
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:30
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:1143
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:3224
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1226
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1101
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3106
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
@ BorderOnly
Draw border only, no background.
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
SortButtonState
State of a sort direction button.
Definition window_gui.h:217
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
@ SBS_UP
Sort descending.
Definition window_gui.h:220
@ WDP_CENTER
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:20
@ WN_NETWORK_WINDOW_CONTENT_LIST
Network content list.
Definition window_type.h:38
@ WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD
Network content download status.
Definition window_type.h:42
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition window_type.h:28
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_NETWORK_WINDOW
Network window; Window numbers:
@ WC_TEXTFILE
textfile; Window numbers:
@ WC_SAVELOAD
Saveload window; Window numbers:
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers: