OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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"
19#include "../base_media_music.h"
21#include "../openttd.h"
22#include "../sortlist_type.h"
24#include "../querystring_gui.h"
26#include "../textbuf_gui.h"
27#include "../textfile_gui.h"
28#include "../fios.h"
29#include "network_content_gui.h"
30
33
34#include "table/strings.h"
35#include "../table/sprites.h"
36
37#include "../safeguards.h"
38
39
41static bool _accepted_external_search = false;
42
49{
50 switch (type) {
51 case ContentType::NewGRF: return STR_CONTENT_TYPE_NEWGRF;
52 case ContentType::BaseGraphics: return STR_CONTENT_TYPE_BASE_GRAPHICS;
53 case ContentType::BaseSounds: return STR_CONTENT_TYPE_BASE_SOUNDS;
54 case ContentType::BaseMusic: return STR_CONTENT_TYPE_BASE_MUSIC;
55 case ContentType::Ai: return STR_CONTENT_TYPE_AI;
56 case ContentType::AiLibrary: return STR_CONTENT_TYPE_AI_LIBRARY;
57 case ContentType::Gs: return STR_CONTENT_TYPE_GAME_SCRIPT;
58 case ContentType::GsLibrary: return STR_CONTENT_TYPE_GS_LIBRARY;
59 case ContentType::Scenario: return STR_CONTENT_TYPE_SCENARIO;
60 case ContentType::Heightmap: return STR_CONTENT_TYPE_HEIGHTMAP;
61 default: NOT_REACHED();
62 }
63}
64
66struct ContentTextfileWindow : public TextfileWindow {
67 const ContentInfo *ci = nullptr;
68
76 {
77 this->ConstructWindow();
78
79 auto textfile = this->ci->GetTextfile(file_type);
80 this->LoadTextfile(textfile.value(), GetContentInfoSubDir(this->ci->type));
81 }
82
83 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
84 {
85 if (widget == WID_TF_CAPTION) {
86 return GetString(stringid, GetContentTypeString(this->ci->type), this->ci->name);
87 }
88
89 return this->Window::GetWidgetString(widget, stringid);
90 }
91};
92
99static void ShowContentTextfileWindow(Window *parent, TextfileType file_type, const ContentInfo *ci)
100{
101 parent->CloseChildWindowById(WindowClass::Textfile, file_type);
102 new ContentTextfileWindow(parent, file_type, ci);
103}
104
106static constexpr std::initializer_list<NWidgetPart> _nested_network_content_download_status_window_widgets = {
107 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
113 EndContainer(),
114 EndContainer(),
115};
116
119 WindowPosition::Center, {}, 0, 0,
120 WindowClass::NetworkStatus, WindowClass::None,
123);
124
132
134{
135 _network_content_client.RemoveCallback(this);
136 this->Window::Close();
137}
138
139void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize)
140{
141 switch (widget) {
143 auto max_value = GetParamMaxDigits(8);
144 size = GetStringBoundingBox(GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, max_value, max_value, max_value));
145 /* We need some spacing for the 'border' */
146 size.height += WidgetDimensions::scaled.frametext.Horizontal();
147 size.width += WidgetDimensions::scaled.frametext.Vertical();
148 break;
149 }
150
153 break;
154 }
155}
156
158{
159 switch (widget) {
161 /* Draw the % complete with a bar and a text */
164 DrawFrameRect(ir.WithWidth((uint64_t)ir.Width() * this->downloaded_bytes / this->total_bytes, _current_text_dir == TD_RTL), Colours::Mauve, {});
165 DrawString(ir.left, ir.right, CentreBounds(ir.top, ir.bottom, GetCharacterHeight(FontSize::Normal)),
166 GetString(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE, this->downloaded_bytes, this->total_bytes, this->downloaded_bytes * 100LL / this->total_bytes),
168 break;
169 }
170
172 if (this->downloaded_bytes == this->total_bytes) {
174 } else if (!this->name.empty()) {
176 GetString(STR_CONTENT_DOWNLOAD_FILE, this->name, this->downloaded_files, this->total_files),
178 } else {
180 }
181 break;
182 }
183}
184
186{
187 if (ci.id != this->cur_id) {
188 this->name = ci.filename;
189 this->cur_id = ci.id;
190 this->downloaded_files++;
191 }
192
193 /* A negative value means we are resetting; for example, when retrying or using a fallback. */
194 if (bytes < 0) {
195 this->downloaded_bytes = 0;
196 } else {
197 this->downloaded_bytes += bytes;
198 }
199
200 this->SetDirty();
201}
202
203
206private:
208
209public:
218
219 void Close([[maybe_unused]] int data = 0) override
220 {
221 TarScanner::Modes modes{};
222 for (auto ctype : this->received_types) {
223 switch (ctype) {
224 case ContentType::Ai:
226 /* AI::Rescan calls the scanner. */
227 break;
228 case ContentType::Gs:
230 /* Game::Rescan calls the scanner. */
231 break;
232
237 break;
238
240 /* ScanNewGRFFiles calls the scanner. */
241 break;
242
246 break;
247
248 default:
249 break;
250 }
251 }
252
253 TarScanner::DoScan(modes);
254
255 /* Tell all the backends about what we've downloaded */
256 for (auto ctype : this->received_types) {
257 switch (ctype) {
258 case ContentType::Ai:
260 AI::Rescan();
261 break;
262
263 case ContentType::Gs:
265 Game::Rescan();
266 break;
267
270 SetWindowDirty(WindowClass::GameOptions, GameOptionsWindowNumber::GameOptions);
271 break;
272
275 SetWindowDirty(WindowClass::GameOptions, GameOptionsWindowNumber::GameOptions);
276 break;
277
280 SetWindowDirty(WindowClass::GameOptions, GameOptionsWindowNumber::GameOptions);
281 break;
282
285 break;
286
290 InvalidateWindowData(WindowClass::SaveLoad, 0, 0);
291 break;
292
293 default:
294 break;
295 }
296 }
297
298 /* Always invalidate the download window; tell it we are going to be gone */
300
302 }
303
304 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
305 {
306 if (widget == WID_NCDS_CANCELOK) {
307 if (this->downloaded_bytes != this->total_bytes) {
309 this->Close();
310 } else {
311 /* If downloading succeeded, close the online content window. This will close
312 * the current window as well. */
314 }
315 }
316 }
317
318 void OnDownloadProgress(const ContentInfo &ci, int64_t bytes) override
319 {
321 this->received_types.Set(ci.type);
322
323 /* When downloading is finished change cancel in ok */
324 if (this->downloaded_bytes == this->total_bytes) {
325 this->GetWidget<NWidgetCore>(WID_NCDS_CANCELOK)->SetString(STR_BUTTON_OK);
326 }
327 }
328};
329
335
341
346
347 static const uint EDITBOX_MAX_SIZE = 50;
348
349 static Listing last_sorting;
351 static const std::initializer_list<GUIContentList::SortFunction * const> sorter_funcs;
352 static const std::initializer_list<GUIContentList::FilterFunction * const> filter_funcs;
354 bool auto_select = false;
358
359 const ContentInfo *selected = nullptr;
360 int list_pos = 0;
361 uint64_t filesize_sum = 0;
362 Scrollbar *vscroll = nullptr;
363
365
368 {
369 std::string url;
370 url.reserve(1024);
371
372 url += "https://grfsearch.openttd.org/?";
373
374 if (this->auto_select) {
375 url += "do=searchgrfid&q=";
376
377 bool first = true;
378 for (const ContentInfo *ci : this->content) {
379 if (ci->state != ContentInfo::State::DoesNotExist) continue;
380
381 if (!first) url.push_back(',');
382 first = false;
383
384 format_append(url, "{:08X}:{}", ci->unique_id, FormatArrayAsHex(ci->md5sum));
385 }
386 } else {
387 url += "do=searchtext&q=";
388
389 /* Escape search term */
390 for (char search : this->filter_editbox.text.GetText()) {
391 /* Remove quotes */
392 if (search == '\'' || search == '"') continue;
393
394 /* Escape special chars, such as &%,= */
395 if (static_cast<unsigned char>(search) < 0x30) {
396 format_append(url, "%{:02X}", search);
397 } else {
398 url.push_back(search);
399 }
400 }
401 }
402
403 OpenBrowser(url);
404 }
405
411 static void ExternalSearchDisclaimerCallback(Window *w, bool accepted)
412 {
413 if (accepted) {
415 ((NetworkContentListWindow*)w)->OpenExternalSearch();
416 }
417 }
418
424 {
425 if (!this->content.NeedRebuild()) return;
426
427 /* Create temporary array of games to use for listing */
428 this->content.clear();
429
430 bool all_available = true;
431
432 for (const ContentInfo &ci : _network_content_client.Info()) {
433 if (ci.state == ContentInfo::State::DoesNotExist) all_available = false;
434 this->content.push_back(&ci);
435 }
436
437 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
438
439 this->FilterContentList();
440 this->content.RebuildDone();
441 this->SortContentList();
442
443 this->vscroll->SetCount(this->content.size()); // Update the scrollbar
444 this->ScrollToSelected();
445 }
446
448 static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
449 {
450 int r = StrNaturalCompare(a->name, b->name, true); // Sort by name (natural sorting).
451 if (r == 0) r = StrNaturalCompare(a->version, b->version, true);
452 return r < 0;
453 }
454
456 static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
457 {
458 int r = 0;
459 if (a->type != b->type) {
461 }
462 if (r == 0) return NameSorter(a, b);
463 return r < 0;
464 }
465
467 static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
468 {
469 int r = to_underlying(a->state) - to_underlying(b->state);
470 if (r == 0) return TypeSorter(a, b);
471 return r < 0;
472 }
473
476 {
477 if (!this->content.Sort()) return;
478
479 int idx = find_index(this->content, this->selected);
480 if (idx >= 0) this->list_pos = idx;
481 }
482
484 static bool TagNameFilter(const ContentInfo * const *item, ContentListFilterData &filter)
485 {
486 if ((*item)->state == ContentInfo::State::Selected || (*item)->state == ContentInfo::State::Autoselected) return true;
487
488 filter.string_filter.ResetState();
489 for (auto &tag : (*item)->tags) filter.string_filter.AddLine(tag);
490
491 filter.string_filter.AddLine((*item)->name);
492 return filter.string_filter.GetState();
493 }
494
496 static bool TypeOrSelectedFilter(const ContentInfo * const *item, ContentListFilterData &filter)
497 {
498 if (filter.types.None()) return true;
499 if (filter.types.Test((*item)->type)) return true;
500 return ((*item)->state == ContentInfo::State::Selected || (*item)->state == ContentInfo::State::Autoselected);
501 }
502
505 {
506 /* Apply filters. */
507 bool changed = false;
508 if (!this->filter_data.string_filter.IsEmpty()) {
509 this->content.SetFilterType(CONTENT_FILTER_TEXT);
510 changed |= this->content.Filter(this->filter_data);
511 }
512 if (this->filter_data.types.Any()) {
514 changed |= this->content.Filter(this->filter_data);
515 }
516 if (!changed) return;
517
518 /* update list position */
519 int idx = find_index(this->content, this->selected);
520 if (idx >= 0) {
521 this->list_pos = idx;
522 return;
523 }
524
525 /* previously selected item not in list anymore */
526 this->selected = nullptr;
527 this->list_pos = 0;
528 }
529
535 {
536 Filtering old_params = this->content.GetFiltering();
537 bool new_state = !this->filter_data.string_filter.IsEmpty() || this->filter_data.types.Any();
538 if (new_state != old_params.state) {
539 this->content.SetFilterState(new_state);
540 }
541 return new_state != old_params.state;
542 }
543
546 {
547 if (this->selected == nullptr) return;
548
549 this->vscroll->ScrollTowards(this->list_pos);
550 }
551
553public:
563 NetworkContentListWindow(WindowDesc &desc, bool select_all, ContentTypes types) :
564 Window(desc),
565 auto_select(select_all),
567 {
568 this->CreateNestedTree();
569 this->vscroll = this->GetScrollbar(WID_NCL_SCROLLBAR);
571
572 this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
573
574 this->querystrings[WID_NCL_FILTER] = &this->filter_editbox;
575 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
577 this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
578 this->filter_data.types = types;
579
580 _network_content_client.AddCallback(this);
581 this->content.SetListing(this->last_sorting);
582 this->content.SetFiltering(this->last_filtering);
583 this->content.SetSortFuncs(this->sorter_funcs);
584 this->content.SetFilterFuncs(this->filter_funcs);
585 this->UpdateFilterState();
586 this->content.ForceRebuild();
587 this->FilterContentList();
588 this->SortContentList();
589 this->InvalidateData();
590 }
591
592 void Close([[maybe_unused]] int data = 0) override
593 {
594 _network_content_client.RemoveCallback(this);
595 this->Window::Close();
596 }
597
598 void OnInit() override
599 {
600 this->checkbox_size = maxdim(maxdim(GetScaledSpriteSize(SPR_BOX_EMPTY), GetScaledSpriteSize(SPR_BOX_CHECKED)), GetScaledSpriteSize(SPR_BLOT));
601 }
602
603 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
604 {
605 switch (widget) {
606 case WID_NCL_CHECKBOX:
607 size.width = std::max<uint>(this->checkbox_size.width, Window::SortButtonWidth()) + padding.width;
608 break;
609
610 case WID_NCL_TYPE: {
611 /* Width must be enough for header label and sort buttons.*/
612 size.width += Window::SortButtonWidth() * 2;
613 /* And also enough for the width of each type of content. */
614 Dimension d = size;
617 }
618 size.width = std::max(size.width, d.width + padding.width);
619 break;
620 }
621
622 case WID_NCL_NAME:
623 size.width += Window::SortButtonWidth() * 2;
624 break;
625
626 case WID_NCL_MATRIX:
627 fill.height = resize.height = std::max<uint>(std::max<uint>(this->checkbox_size.height, GetCharacterHeight(FontSize::Normal)), GetCharacterHeight(FontSize::Small)) + padding.height;
628 size.height = 10 * resize.height;
629 break;
630 }
631 }
632
633
634 void DrawWidget(const Rect &r, WidgetID widget) const override
635 {
636 switch (widget) {
637 case WID_NCL_DETAILS:
638 this->DrawDetails(r);
639 break;
640
641 case WID_NCL_MATRIX:
642 this->DrawMatrix(r);
643 break;
644 }
645 }
646
647 void OnPaint() override
648 {
649 if (this->content.NeedRebuild()) {
650 this->BuildContentList();
651 }
652
653 this->DrawWidgets();
654 this->DrawSortButton(this->content.SortType() + WID_NCL_CHECKBOX, this->content.IsDescSortOrder());
655 }
656
661 void DrawMatrix(const Rect &r) const
662 {
663 bool rtl = _current_text_dir == TD_RTL;
664 const Rect checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX)->GetCurrentRect();
665 const Rect name = this->GetWidget<NWidgetBase>(WID_NCL_NAME)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
666 const Rect type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
667
668 /* Fill the matrix with the information */
669 const uint step_height = this->GetWidget<NWidgetBase>(WID_NCL_MATRIX)->resize_y;
670 const int text_y_offset = WidgetDimensions::scaled.matrix.top + (step_height - WidgetDimensions::scaled.matrix.Vertical() - GetCharacterHeight(FontSize::Normal)) / 2;
671 const int version_y_offset = WidgetDimensions::scaled.matrix.top + (step_height - WidgetDimensions::scaled.matrix.Vertical() - GetCharacterHeight(FontSize::Small)) / 2;
672
673 Rect mr = r.WithHeight(step_height);
674 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->content);
675 for (auto iter = first; iter != last; iter++) {
676 const ContentInfo *ci = *iter;
677
678 if (ci == this->selected) GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), PC_GREY);
679
680 SpriteID sprite;
681 SpriteID pal = PAL_NONE;
682 switch (ci->state) {
683 case ContentInfo::State::Unselected: sprite = SPR_BOX_EMPTY; break;
684 case ContentInfo::State::Selected: sprite = SPR_BOX_CHECKED; break;
685 case ContentInfo::State::Autoselected: sprite = SPR_BOX_CHECKED; break;
686 case ContentInfo::State::AlreadyHere: sprite = SPR_BLOT; pal = PALETTE_TO_GREEN; break;
687 case ContentInfo::State::DoesNotExist: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break;
688 default: NOT_REACHED();
689 }
690 DrawSpriteIgnorePadding(sprite, pal, checkbox.WithY(mr), {AlignmentH::Centre, AlignmentV::Middle});
691
693 DrawString(type.left, type.right, mr.top + text_y_offset, str, TextColour::Black, AlignmentH::Centre);
694
695 int x = DrawString(name.left, name.right, mr.top + version_y_offset, ci->version, TextColour::Black, AlignmentH::End, false, FontSize::Small);
696 x += rtl ? WidgetDimensions::scaled.hsep_wide : -WidgetDimensions::scaled.hsep_wide;
697
698 DrawString(rtl ? x : name.left, rtl ? name.right : x, mr.top + text_y_offset, ci->name, TextColour::Black);
699 mr = mr.Translate(0, step_height);
700 }
701 }
702
707 void DrawDetails(const Rect &r) const
708 {
709 /* Height for the title banner */
710 int HEADER_HEIGHT = 3 * GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.frametext.Vertical();
711
712 Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.frametext);
713 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
714 tr.top += HEADER_HEIGHT;
715
716 /* Create the nice darker rectangle at the details top */
718 DrawString(hr.left, hr.right, hr.top, STR_CONTENT_DETAIL_TITLE, TextColour::FromString, AlignmentH::Centre);
719
720 /* Draw the total download size */
721 DrawString(tr.left, tr.right, tr.bottom - GetCharacterHeight(FontSize::Normal) + 1, GetString(STR_CONTENT_TOTAL_DOWNLOAD_SIZE, this->filesize_sum));
722
723 if (this->selected == nullptr) return;
724
725 /* And fill the rest of the details when there's information to place there */
726 DrawStringMultiLine(hr.left, hr.right, hr.top + GetCharacterHeight(FontSize::Normal), hr.bottom, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + to_underlying(this->selected->state), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle});
727
728 /* Also show the total download size, so keep some space from the bottom */
730
731 if (this->selected->upgrade) {
732 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_UPDATE, GetContentTypeString(this->selected->type)));
733 tr.top += WidgetDimensions::scaled.vsep_wide;
734 }
735
736 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_NAME, this->selected->name));
737
738 if (!this->selected->version.empty()) {
739 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_VERSION, this->selected->version));
740 }
741
742 if (!this->selected->description.empty()) {
743 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_DESCRIPTION, this->selected->description));
744 }
745
746 if (!this->selected->url.empty()) {
747 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_URL, this->selected->url));
748 }
749
750 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_TYPE, GetContentTypeString(this->selected->type)));
751
752 tr.top += WidgetDimensions::scaled.vsep_wide;
753 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_FILESIZE, this->selected->filesize));
754
755 std::string_view list_separator = GetListSeparator();
756 if (!this->selected->dependencies.empty()) {
757 /* List dependencies */
758 std::string buf;
759 for (auto &cid : this->selected->dependencies) {
760 /* Try to find the dependency */
761 for (const ContentInfo &ci : _network_content_client.Info()) {
762 if (ci.id != cid) continue;
763
764 if (!buf.empty()) buf += list_separator;
765 buf += ci.name;
766 break;
767 }
768 }
769 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_DEPENDENCIES, std::move(buf)));
770 }
771
772 if (!this->selected->tags.empty()) {
773 /* List all tags */
774 std::string buf;
775 for (auto &tag : this->selected->tags) {
776 if (!buf.empty()) buf += list_separator;
777 buf += tag;
778 }
779 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_TAGS, std::move(buf)));
780 }
781
782 if (this->selected->IsSelected()) {
783 /* When selected show all manually selected content that depends on this */
785 _network_content_client.ReverseLookupTreeDependency(tree, this->selected);
786
787 std::string buf;
788 for (const ContentInfo *ci : tree) {
789 if (ci == this->selected || ci->state != ContentInfo::State::Selected) continue;
790
791 if (!buf.empty()) buf += list_separator;
792 buf += ci->name;
793 }
794 if (!buf.empty()) {
795 tr.top = DrawStringMultiLine(tr, GetString(STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF, std::move(buf)));
796 }
797 }
798 }
799
800 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
801 {
802 if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TextfileType::ContentEnd) {
803 if (this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere) return;
804
805 ShowContentTextfileWindow(this, (TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
806 return;
807 }
808
809 switch (widget) {
810 case WID_NCL_MATRIX: {
811 auto it = this->vscroll->GetScrolledItemFromWidget(this->content, pt.y, this, WID_NCL_MATRIX);
812 if (it == this->content.end()) return; // click out of bounds
813
814 const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
815 if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
816 _network_content_client.ToggleSelectedState(**it);
817 this->content.ForceResort();
818 this->content.ForceRebuild();
819 } else {
820 this->selected = *it;
821 this->list_pos = it - this->content.begin();
822 }
823
824 if (this->filter_data.types.Any()) {
825 this->content.ForceRebuild();
826 }
827
828 this->InvalidateData();
829 break;
830 }
831
832 case WID_NCL_CHECKBOX:
833 case WID_NCL_TYPE:
834 case WID_NCL_NAME:
835 if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
836 this->content.ToggleSortOrder();
837 if (!this->content.empty()) this->list_pos = (int)this->content.size() - this->list_pos - 1;
838 } else {
839 this->content.SetSortType(widget - WID_NCL_CHECKBOX);
840 this->content.ForceResort();
841 this->SortContentList();
842 }
843 this->ScrollToSelected();
844 this->InvalidateData();
845 break;
846
848 _network_content_client.SelectAll();
849 this->InvalidateData();
850 break;
851
853 _network_content_client.SelectUpgrade();
854 this->InvalidateData();
855 break;
856
857 case WID_NCL_UNSELECT:
858 _network_content_client.UnselectAll();
859 this->InvalidateData();
860 break;
861
862 case WID_NCL_OPEN_URL:
863 if (this->selected != nullptr) {
864 OpenBrowser(this->selected->url);
865 }
866 break;
867
868 case WID_NCL_DOWNLOAD:
870 break;
871
874 this->OpenExternalSearch();
875 } else {
876 ShowQuery(
877 GetEncodedString(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER_CAPTION),
878 GetEncodedString(STR_CONTENT_SEARCH_EXTERNAL_DISCLAIMER),
880 }
881 break;
882 }
883 }
884
885 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
886 {
887 if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == EventState::NotHandled) {
888 switch (keycode) {
889 case WKC_SPACE:
890 case WKC_RETURN:
891 if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
892 if (this->selected != nullptr) {
893 _network_content_client.ToggleSelectedState(*this->selected);
894 this->content.ForceResort();
895 this->InvalidateData();
896 }
897 if (this->filter_data.types.Any()) {
898 this->content.ForceRebuild();
899 this->InvalidateData();
900 }
901 return EventState::Handled;
902 }
903 /* space is pressed and filter is focused. */
904 [[fallthrough]];
905
906 default:
908 }
909 }
910
911 if (this->content.empty()) {
912 if (this->UpdateFilterState()) {
913 this->content.ForceRebuild();
914 this->InvalidateData();
915 }
916 return EventState::Handled;
917 }
918
919 this->selected = this->content[this->list_pos];
920
921 if (this->UpdateFilterState()) {
922 this->content.ForceRebuild();
923 } else {
924 /* Scroll to the new content if it is outside the current range. */
925 this->ScrollToSelected();
926 }
927
928 /* redraw window */
929 this->InvalidateData();
930 return EventState::Handled;
931 }
932
933 void OnEditboxChanged(WidgetID wid) override
934 {
935 if (wid == WID_NCL_FILTER) {
936 this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.GetText());
937 this->UpdateFilterState();
938 this->content.ForceRebuild();
939 this->InvalidateData();
940 }
941 }
942
943 void OnResize() override
944 {
945 this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
946 }
947
948 void OnReceiveContentInfo(const ContentInfo &rci) override
949 {
950 if (this->auto_select && !rci.IsSelected()) _network_content_client.ToggleSelectedState(rci);
951 this->content.ForceRebuild();
952 this->InvalidateData(0, false);
953 }
954
956 {
957 this->content.ForceResort();
958 this->InvalidateData();
959 }
960
961 void OnConnect(bool success) override
962 {
963 if (!success) {
964 ShowErrorMessage(GetEncodedString(STR_CONTENT_ERROR_COULD_NOT_CONNECT), {}, WarningLevel::Error);
965 this->Close();
966 return;
967 }
968
969 this->InvalidateData();
970 }
971
977 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
978 {
979 if (!gui_scope) return;
980 if (this->content.NeedRebuild()) this->BuildContentList();
981
982 /* To sum all the bytes we intend to download */
983 this->filesize_sum = 0;
984 bool show_select_all = false;
985 bool show_select_upgrade = false;
986 for (const ContentInfo *ci : this->content) {
987 switch (ci->state) {
990 this->filesize_sum += ci->filesize;
991 break;
992
994 show_select_all = true;
995 show_select_upgrade |= ci->upgrade;
996 break;
997
998 default:
999 break;
1000 }
1001 }
1002
1003 /* If data == 2 then the status window caused this OnInvalidate */
1004 this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WindowClass::NetworkStatus, NetworkStatusWindowNumber::ContentDownload) != nullptr && data != 2));
1005 this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
1006 this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
1007 this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade || !this->filter_data.string_filter.IsEmpty());
1008 this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
1010 this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere || !this->selected->GetTextfile(tft).has_value());
1011 }
1012 }
1013};
1014
1017
1018const std::initializer_list<NetworkContentListWindow::GUIContentList::SortFunction * const> NetworkContentListWindow::sorter_funcs = {
1019 &StateSorter,
1020 &TypeSorter,
1021 &NameSorter,
1022};
1023
1024const std::initializer_list<NetworkContentListWindow::GUIContentList::FilterFunction * const> NetworkContentListWindow::filter_funcs = {
1027};
1028
1030
1040
1042static constexpr std::initializer_list<NWidgetPart> _nested_network_content_list_widgets = {
1045 NWidget(WWT_CAPTION, Colours::LightBlue), SetStringTip(STR_CONTENT_TITLE),
1047 EndContainer(),
1050 /* Top */
1054 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1055 EndContainer(),
1056 /* Lists and info. */
1058 /* Left side. */
1065 SetStringTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
1067 SetStringTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
1068 EndContainer(),
1070 EndContainer(),
1072 EndContainer(),
1076 SetStringTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
1078 SetStringTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
1079 EndContainer(),
1081 SetStringTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
1082 EndContainer(),
1083 EndContainer(),
1084 /* Right side. */
1087 EndContainer(),
1090 NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1091 NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1092 EndContainer(),
1094 NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1095 NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1096 EndContainer(),
1097 EndContainer(),
1098 EndContainer(),
1099 EndContainer(),
1100 /* Bottom. */
1103 SetStringTip(STR_CONTENT_SEARCH_EXTERNAL, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP),
1105 SetStringTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
1106 EndContainer(),
1107 EndContainer(),
1108 /* Resize button. */
1110 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1112 EndContainer(),
1113 EndContainer(),
1114};
1115
1118 WindowPosition::Center, "list_content", 630, 460,
1119 WindowClass::Network, WindowClass::None,
1120 {},
1122);
1123
1132{
1133#if defined(WITH_ZLIB)
1134 ContentTypes types{};
1136 if (cv == nullptr) {
1137 assert(type1 != ContentType::End || type2 == ContentType::End);
1138 assert(type1 == ContentType::End || type1 != type2);
1139 _network_content_client.RequestContentList(type1);
1140 if (type2 != ContentType::End) _network_content_client.RequestContentList(type2);
1141
1142 if (type1 != ContentType::End) types.Set(type1);
1143 if (type2 != ContentType::End) types.Set(type2);
1144 } else {
1145 _network_content_client.RequestContentList(cv, true);
1146 }
1147
1149 new NetworkContentListWindow(_network_content_list_desc, cv != nullptr, types);
1150#else
1152 GetEncodedString(STR_CONTENT_NO_ZLIB),
1153 GetEncodedString(STR_CONTENT_NO_ZLIB_SUB),
1155#endif /* WITH_ZLIB */
1156}
Base functions for all AIs.
Generic functions for replacing base data (graphics, sounds).
Generic functions for replacing base graphics data.
Generic functions for replacing base music data.
Generic functions for replacing base sounds data.
static void Rescan()
Rescans all searchpaths for available AIs.
Definition ai_core.cpp:312
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
uint32_t cur_id
The current ID of the downloaded file.
BaseNetworkContentDownloadStatusWindow(WindowDesc &desc)
Create the window with the given description.
void OnDownloadProgress(const ContentInfo &ci, int64_t bytes) override
We have progress in the download of a file.
uint total_files
Number of files to download.
uint64_t total_bytes
Number of bytes to download.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
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.
uint64_t downloaded_bytes
Number of bytes downloaded.
uint downloaded_files
Number of files downloaded.
Iterate a range of enum values.
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.
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.
static void Rescan()
Rescans all searchpaths for available Game scripts.
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.
GUIContentList content
List with content.
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.
int list_pos
Our position in the list.
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.
uint64_t filesize_sum
The sum of all selected file sizes.
static bool TypeOrSelectedFilter(const ContentInfo *const *item, ContentListFilterData &filter)
Filter content by type, but still show content selected for download.
bool UpdateFilterState()
Update filter state based on current window state.
void OnPaint() override
The window must be repainted.
NetworkContentListWindow(WindowDesc &desc, bool select_all, ContentTypes types)
Create the content list window.
static EnumIndexArray< std::string, ContentType, ContentType::End > content_type_strs
Cached strings for all content types.
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.
static bool TagNameFilter(const ContentInfo *const *item, ContentListFilterData &filter)
Filter content by tags/name.
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.
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:2548
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:2495
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.
Definition fileio_func.h:67
@ Baseset
Scan for base sets.
Definition fileio_func.h:64
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition fileio.cpp:382
EnumBitSet< Mode, uint8_t > Modes
Bitset of Mode elements.
Definition fileio_func.h:72
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
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_...
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Functions related to errors.
@ Error
Errors (eg. saving/loading failed).
Definition error.h:24
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:713
Declarations for savegames operations.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Base functions for all Games.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
@ Middle
Align to the middle.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:111
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
Functions related to the gfx engine.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:70
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, Alignment align)
Draw a sprite within a Rect, ignoring the sprite's padding.
Definition widget.cpp:350
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Small
Index of the small font in the font tables.
Definition gfx_type.h:250
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ White
White.
Definition gfx_type.h:300
@ Mauve
Mauve.
Definition gfx_type.h:295
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ LightBlue
Light blue.
Definition gfx_type.h:290
@ Grey
Grey.
Definition gfx_type.h:299
@ FromString
Marker for telling to use the colour from the string.
Definition gfx_type.h:317
@ Black
Black colour.
Definition gfx_type.h:334
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 SetResizeWidgetTypeTip(ResizeWidgetType widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
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 EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetAlignment(Alignment 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:1013
#define Point
Macro that prevents name conflicts between included headers.
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...
Types related to the misc widgets.
@ WID_TF_CAPTION
The caption of the window.
Definition misc_widget.h:53
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 void ShowContentTextfileWindow(Window *parent, TextfileType file_type, const ContentInfo *ci)
Open the window with one of the text files associated with content.
static constexpr std::initializer_list< NWidgetPart > _nested_network_content_list_widgets
The widgets for the content list.
static StringID GetContentTypeString(ContentType type)
Get the string associated with a ContentType.
static WindowDesc _network_content_list_desc(WindowPosition::Center, "list_content", 630, 460, WindowClass::Network, WindowClass::None, {}, _nested_network_content_list_widgets)
Window description of the content list.
void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentType type2)
Show the content list window with a given set of content.
static constexpr std::initializer_list< NWidgetPart > _nested_network_content_download_status_window_widgets
Nested widgets for the download window.
static WindowDesc _network_content_download_status_window_desc(WindowPosition::Center, {}, 0, 0, WindowClass::NetworkStatus, WindowClass::None, WindowDefaultFlag::Modal, _nested_network_content_download_status_window_widgets)
Window description for the download window.
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.
void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
User interface for downloading files.
Types related to the network content widgets.
@ 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_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
Some generic types.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
Definition palette.cpp:393
@ Normal
Normal colour shade.
static constexpr PixelColour PC_GREY
Grey palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
Base types for having sorted lists in GUIs.
This file contains all sprite-related enums and defines.
static const PaletteID PALETTE_TO_GREEN
Definition sprites.h:1769
static const PaletteID PALETTE_TO_RED
Definition sprites.h:1767
static const SpriteID SPR_BLOT
Coloured circle (used for server compatibility and installed content).
Definition sprites.h:72
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:76
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:428
Searching and filtering using a stringterm.
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:298
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:217
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > 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 filesize
Size of the file.
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).
@ Unselected
The content has not been selected.
@ AlreadyHere
The content is already at the client side.
@ Selected
The content has been manually selected.
@ Autoselected
The content has been selected as dependency.
@ DoesNotExist
The content does not exist in the content system.
StringList tags
Tags associated with the content.
bool upgrade
This item is an upgrade.
Filter data for NetworkContentListWindow.
StringFilter string_filter
Text filter of content list.
ContentTypes types
Content types displayed.
Window for displaying the textfile of an item in the content list.
ContentTextfileWindow(Window *parent, TextfileType file_type, const ContentInfo *ci)
Create the window with one of the text files associated with content.
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.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
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).
Window for showing the download status of content.
void OnDownloadProgress(const ContentInfo &ci, int64_t bytes) override
We have progress in the download of a file.
ContentTypes received_types
Types we received so we can update their cache.
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.
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.
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 WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordinates.
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.
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:283
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:171
Data structure for an opened window.
Definition window_gui.h:272
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:839
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:319
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
Window * parent
Parent window.
Definition window_gui.h:327
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
bool IsWidgetFocused(WidgetID widget_index) const
Check if given widget is focused within this window.
Definition window_gui.h:419
void DrawSortButton(WidgetID widget, bool descending) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:824
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1137
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:494
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
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 received over the network from the content servers.
@ BaseSounds
The content consists of base sounds.
@ Begin
Helper to mark the begin of the types.
@ GsLibrary
The content consists of a GS library.
@ Scenario
The content consists of a scenario.
@ Heightmap
The content consists of a heightmap.
@ BaseGraphics
The content consists of base graphics.
@ Ai
The content consists of an AI.
@ End
Helper to mark the end of the types.
@ BaseMusic
The content consists of base music.
@ Gs
The content consists of a game script.
@ NewGRF
The content consists of a NewGRF.
@ AiLibrary
The content consists of an AI library.
EnumBitSet< ContentType, uint16_t, ContentType::End > ContentTypes
Bitset of chosen content types.
Stuff related to the text buffer GUI.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
@ Readme
Content readme.
@ ContentBegin
This marker is used to generate the below three buttons in sequence by various of places in the code.
@ ContentEnd
This marker is used to generate the above three buttons in sequence by various of places in the code.
@ License
Content license.
@ Changelog
Content changelog.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ HideBevel
Bevel of resize box is hidden.
Definition widget_type.h:29
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:1242
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:3377
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1199
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3255
Window functions not directly related to making/drawing windows.
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition window_gui.h:155
@ BorderOnly
Draw border only, no background.
Definition window_gui.h:25
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:26
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.
@ GameOptions
Game options.
Definition window_type.h:32
@ ContentDownload
Network content download status.
Definition window_type.h:57
@ ContentList
Network content list.
Definition window_type.h:50