OpenTTD Source  20240915-master-g3784a3d3d6
picker_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 "core/backup_type.hpp"
12 #include "gui.h"
13 #include "hotkeys.h"
14 #include "ini_type.h"
15 #include "picker_gui.h"
16 #include "querystring_gui.h"
17 #include "settings_type.h"
18 #include "sortlist_type.h"
19 #include "sound_func.h"
20 #include "sound_type.h"
21 #include "string_func.h"
22 #include "stringfilter_type.h"
23 #include "strings_func.h"
24 #include "widget_type.h"
25 #include "window_func.h"
26 #include "window_gui.h"
27 #include "window_type.h"
28 #include "zoom_func.h"
29 
30 #include "widgets/picker_widget.h"
31 
32 #include "table/sprites.h"
33 
34 #include <charconv>
35 
36 #include "safeguards.h"
37 
38 static std::vector<PickerCallbacks *> &GetPickerCallbacks()
39 {
40  static std::vector<PickerCallbacks *> callbacks;
41  return callbacks;
42 }
43 
44 PickerCallbacks::PickerCallbacks(const std::string &ini_group) : ini_group(ini_group)
45 {
46  GetPickerCallbacks().push_back(this);
47 }
48 
49 PickerCallbacks::~PickerCallbacks()
50 {
51  auto &callbacks = GetPickerCallbacks();
52  callbacks.erase(std::find(callbacks.begin(), callbacks.end(), this));
53 }
54 
60 static void PickerLoadConfig(const IniFile &ini, PickerCallbacks &callbacks)
61 {
62  const IniGroup *group = ini.GetGroup(callbacks.ini_group);
63  if (group == nullptr) return;
64 
65  callbacks.saved.clear();
66  for (const IniItem &item : group->items) {
67  std::array<uint8_t, 4> grfid_buf;
68 
69  std::string_view str = item.name;
70 
71  /* Try reading "<grfid>|<localid>" */
72  auto grfid_pos = str.find('|');
73  if (grfid_pos == std::string_view::npos) continue;
74 
75  std::string_view grfid_str = str.substr(0, grfid_pos);
76  if (!ConvertHexToBytes(grfid_str, grfid_buf)) continue;
77 
78  str = str.substr(grfid_pos + 1);
79  uint32_t grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
80  uint16_t localid;
81  auto [ptr, err] = std::from_chars(str.data(), str.data() + str.size(), localid);
82 
83  if (err == std::errc{} && ptr == str.data() + str.size()) {
84  callbacks.saved.insert({grfid, localid, 0, 0});
85  }
86  }
87 }
88 
94 static void PickerSaveConfig(IniFile &ini, const PickerCallbacks &callbacks)
95 {
96  IniGroup &group = ini.GetOrCreateGroup(callbacks.ini_group);
97  group.Clear();
98 
99  for (const PickerItem &item : callbacks.saved) {
100  std::string key = fmt::format("{:08X}|{}", BSWAP32(item.grfid), item.local_id);
101  group.CreateItem(key);
102  }
103 }
104 
109 void PickerLoadConfig(const IniFile &ini)
110 {
111  for (auto *cb : GetPickerCallbacks()) PickerLoadConfig(ini, *cb);
112 }
113 
119 {
120  for (const auto *cb : GetPickerCallbacks()) PickerSaveConfig(ini, *cb);
121 }
122 
124 static bool ClassIDSorter(int const &a, int const &b)
125 {
126  return a < b;
127 }
128 
130 static bool ClassTagNameFilter(int const *item, PickerFilterData &filter)
131 {
132  filter.ResetState();
133  filter.AddLine(GetString(filter.callbacks->GetClassName(*item)));
134  return filter.GetState();
135 }
136 
138 static bool TypeIDSorter(PickerItem const &a, PickerItem const &b)
139 {
140  int r = a.class_index - b.class_index;
141  if (r == 0) r = a.index - b.index;
142  return r < 0;
143 }
144 
146 static bool TypeTagNameFilter(PickerItem const *item, PickerFilterData &filter)
147 {
148  filter.ResetState();
149  filter.AddLine(GetString(filter.callbacks->GetTypeName(item->class_index, item->index)));
150  return filter.GetState();
151 }
152 
153 static const std::initializer_list<PickerClassList::SortFunction * const> _class_sorter_funcs = { &ClassIDSorter };
154 static const std::initializer_list<PickerClassList::FilterFunction * const> _class_filter_funcs = { &ClassTagNameFilter };
155 static const std::initializer_list<PickerTypeList::SortFunction * const> _type_sorter_funcs = { TypeIDSorter };
156 static const std::initializer_list<PickerTypeList::FilterFunction * const> _type_filter_funcs = { TypeTagNameFilter };
157 
158 PickerWindow::PickerWindow(WindowDesc &desc, Window *parent, int window_number, PickerCallbacks &callbacks) : PickerWindowBase(desc, parent), callbacks(callbacks),
159  class_editbox(EDITBOX_MAX_SIZE * MAX_CHAR_LENGTH, EDITBOX_MAX_SIZE),
160  type_editbox(EDITBOX_MAX_SIZE * MAX_CHAR_LENGTH, EDITBOX_MAX_SIZE)
161 {
162  this->window_number = window_number;
163 
164  /* Init of nested tree is deferred.
165  * PickerWindow::ConstructWindow must be called by the inheriting window. */
166 }
167 
168 void PickerWindow::ConstructWindow()
169 {
170  this->CreateNestedTree();
171 
172  /* Test if pickers should be active.*/
173  bool isActive = this->callbacks.IsActive();
174 
175  /* Functionality depends on widgets being present, not window class. */
176  this->has_class_picker = isActive && this->GetWidget<NWidgetBase>(WID_PW_CLASS_LIST) != nullptr && this->callbacks.HasClassChoice();
177  this->has_type_picker = isActive && this->GetWidget<NWidgetBase>(WID_PW_TYPE_MATRIX) != nullptr;
178 
179  if (this->has_class_picker) {
180  this->GetWidget<NWidgetCore>(WID_PW_CLASS_LIST)->tool_tip = this->callbacks.GetClassTooltip();
181 
183  } else {
184  if (auto *nwid = this->GetWidget<NWidgetStacked>(WID_PW_CLASS_SEL); nwid != nullptr) {
185  /* Check the container orientation. MakeNWidgets adds an additional NWID_VERTICAL container so we check the grand-parent. */
186  bool is_vertical = (nwid->parent->parent->type == NWID_VERTICAL);
187  nwid->SetDisplayedPlane(is_vertical ? SZSP_HORIZONTAL : SZSP_VERTICAL);
188  }
189  }
190 
192  this->class_string_filter.SetFilterTerm(this->class_editbox.text.buf);
193  this->class_string_filter.callbacks = &this->callbacks;
194 
195  this->classes.SetListing(this->callbacks.class_last_sorting);
196  this->classes.SetFiltering(this->callbacks.class_last_filtering);
197  this->classes.SetSortFuncs(_class_sorter_funcs);
198  this->classes.SetFilterFuncs(_class_filter_funcs);
199 
200  if (this->has_type_picker) {
201  /* Update used and saved type information. */
202  this->callbacks.saved = this->callbacks.UpdateSavedItems(this->callbacks.saved);
203  this->callbacks.used.clear();
204  this->callbacks.FillUsedItems(this->callbacks.used);
205 
207 
208  this->GetWidget<NWidgetCore>(WID_PW_TYPE_ITEM)->tool_tip = this->callbacks.GetTypeTooltip();
209 
210  auto *matrix = this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX);
211  matrix->SetScrollbar(this->GetScrollbar(WID_PW_TYPE_SCROLL));
212 
214  } else {
215  if (auto *nwid = this->GetWidget<NWidgetStacked>(WID_PW_TYPE_SEL); nwid != nullptr) {
216  /* Check the container orientation. MakeNWidgets adds an additional NWID_VERTICAL container so we check the grand-parent. */
217  bool is_vertical = (nwid->parent->parent->type == NWID_VERTICAL);
218  nwid->SetDisplayedPlane(is_vertical ? SZSP_HORIZONTAL : SZSP_VERTICAL);
219  }
220  }
221 
223  this->type_string_filter.SetFilterTerm(this->type_editbox.text.buf);
224  this->type_string_filter.callbacks = &this->callbacks;
225 
226  this->types.SetListing(this->callbacks.type_last_sorting);
227  this->types.SetFiltering(this->callbacks.type_last_filtering);
228  this->types.SetSortFuncs(_type_sorter_funcs);
229  this->types.SetFilterFuncs(_type_filter_funcs);
230 
231  this->FinishInitNested(this->window_number);
232 
234 }
235 
236 void PickerWindow::Close(int data)
237 {
238  this->callbacks.Close(data);
239  this->PickerWindowBase::Close(data);
240 }
241 
242 void PickerWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize)
243 {
244  switch (widget) {
245  /* Class picker */
246  case WID_PW_CLASS_LIST:
247  resize.height = GetCharacterHeight(FS_NORMAL) + padding.height;
248  size.height = 5 * resize.height;
249  break;
250 
251  /* Type picker */
252  case WID_PW_TYPE_MATRIX:
253  /* At least two items wide. */
254  size.width += resize.width;
255  fill.width = resize.width;
256  fill.height = 1;
257 
258  /* Resizing in X direction only at blob size, but at pixel level in Y. */
259  resize.height = 1;
260  break;
261 
262  /* Type picker */
263  case WID_PW_TYPE_ITEM:
266  break;
267  }
268 }
269 
270 void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const
271 {
272  switch (widget) {
273  /* Class picker */
274  case WID_PW_CLASS_LIST: {
275  Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
276  const int selected = this->callbacks.GetSelectedClass();
277  const auto vscroll = this->GetScrollbar(WID_PW_CLASS_SCROLL);
278  const int y_step = this->GetWidget<NWidgetResizeBase>(widget)->resize_y;
279  auto [first, last] = vscroll->GetVisibleRangeIterators(this->classes);
280  for (auto it = first; it != last; ++it) {
281  DrawString(ir, this->callbacks.GetClassName(*it), *it == selected ? TC_WHITE : TC_BLACK);
282  ir.top += y_step;
283  }
284  break;
285  }
286 
287  /* Type picker */
288  case WID_PW_TYPE_ITEM: {
289  assert(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement() < static_cast<int>(this->types.size()));
290  const auto &item = this->types[this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement()];
291 
292  DrawPixelInfo tmp_dpi;
293  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
294  if (FillDrawPixelInfo(&tmp_dpi, ir)) {
295  AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
298 
299  this->callbacks.DrawType(x, y, item.class_index, item.index);
300  if (this->callbacks.saved.contains(item)) {
301  DrawSprite(SPR_BLOT, PALETTE_TO_YELLOW, 0, 0);
302  }
303  if (this->callbacks.used.contains(item)) {
304  DrawSprite(SPR_BLOT, PALETTE_TO_GREEN, ir.Width() - GetSpriteSize(SPR_BLOT).width, 0);
305  }
306  }
307 
308  if (!this->callbacks.IsTypeAvailable(item.class_index, item.index)) {
309  GfxFillRect(ir, GetColourGradient(COLOUR_GREY, SHADE_DARKER), FILLRECT_CHECKER);
310  }
311  break;
312  }
313 
314  case WID_PW_TYPE_NAME:
315  DrawString(r, this->callbacks.GetTypeName(this->callbacks.GetSelectedClass(), this->callbacks.GetSelectedType()), TC_ORANGE, SA_CENTER);
316  break;
317  }
318 }
319 
321 {
322  if (this->has_class_picker) {
324  }
325 }
326 
327 void PickerWindow::OnClick(Point pt, WidgetID widget, int)
328 {
329  switch (widget) {
330  /* Class Picker */
331  case WID_PW_CLASS_LIST: {
332  const auto vscroll = this->GetWidget<NWidgetScrollbar>(WID_PW_CLASS_SCROLL);
333  auto it = vscroll->GetScrolledItemFromWidget(this->classes, pt.y, this, WID_PW_CLASS_LIST);
334  if (it == this->classes.end()) return;
335 
336  if (this->callbacks.GetSelectedClass() != *it || HasBit(this->callbacks.mode, PFM_ALL)) {
337  ClrBit(this->callbacks.mode, PFM_ALL); // Disable showing all.
338  this->callbacks.SetSelectedClass(*it);
340  }
343  break;
344  }
345 
346  case WID_PW_MODE_ALL:
347  case WID_PW_MODE_USED:
348  case WID_PW_MODE_SAVED:
349  ToggleBit(this->callbacks.mode, widget - WID_PW_MODE_ALL);
350  if (!this->IsWidgetDisabled(WID_PW_MODE_ALL) && HasBit(this->callbacks.mode, widget - WID_PW_MODE_ALL)) {
351  /* Enabling used or saved filters automatically enables all. */
352  SetBit(this->callbacks.mode, PFM_ALL);
353  }
355  break;
356 
357  /* Type Picker */
358  case WID_PW_TYPE_ITEM: {
359  int sel = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
360  assert(sel < (int)this->types.size());
361  const auto &item = this->types[sel];
362 
363  if (_ctrl_pressed) {
364  auto it = this->callbacks.saved.find(item);
365  if (it == std::end(this->callbacks.saved)) {
366  this->callbacks.saved.insert(item);
367  } else {
368  this->callbacks.saved.erase(it);
369  }
370  this->InvalidateData(PFI_TYPE);
371  break;
372  }
373 
374  if (this->callbacks.IsTypeAvailable(item.class_index, item.index)) {
375  this->callbacks.SetSelectedClass(item.class_index);
376  this->callbacks.SetSelectedType(item.index);
378  }
381  break;
382  }
383  }
384 }
385 
386 void PickerWindow::OnInvalidateData(int data, bool gui_scope)
387 {
388  if (!gui_scope) return;
389 
390  if ((data & PFI_CLASS) != 0) this->classes.ForceRebuild();
391  if ((data & PFI_TYPE) != 0) this->types.ForceRebuild();
392 
393  this->BuildPickerClassList();
394  if ((data & PFI_VALIDATE) != 0) this->EnsureSelectedClassIsValid();
395  if ((data & PFI_POSITION) != 0) this->EnsureSelectedClassIsVisible();
396 
397  this->BuildPickerTypeList();
398  if ((data & PFI_VALIDATE) != 0) this->EnsureSelectedTypeIsValid();
399  if ((data & PFI_POSITION) != 0) this->EnsureSelectedTypeIsVisible();
400 
401  if (this->has_type_picker) {
405  }
406 }
407 
409 {
410  switch (hotkey) {
412  /* Cycle between the two edit boxes. */
413  if (this->has_type_picker && (this->nested_focus == nullptr || this->nested_focus->index != WID_PW_TYPE_FILTER)) {
415  } else if (this->has_class_picker && (this->nested_focus == nullptr || this->nested_focus->index != WID_PW_CLASS_FILTER)) {
417  }
418  SetFocusedWindow(this);
419  return ES_HANDLED;
420 
421  default:
422  return ES_NOT_HANDLED;
423  }
424 }
425 
426 void PickerWindow::OnEditboxChanged(WidgetID wid)
427 {
428  switch (wid) {
429  case WID_PW_CLASS_FILTER:
430  this->class_string_filter.SetFilterTerm(this->class_editbox.text.buf);
431  this->classes.SetFilterState(!class_string_filter.IsEmpty());
432  this->InvalidateData(PFI_CLASS);
433  break;
434 
435  case WID_PW_TYPE_FILTER:
436  this->type_string_filter.SetFilterTerm(this->type_editbox.text.buf);
437  this->types.SetFilterState(!type_string_filter.IsEmpty());
438  this->InvalidateData(PFI_TYPE);
439  break;
440 
441  default:
442  break;
443  }
444 }
445 
448 {
449  if (!this->classes.NeedRebuild()) return;
450 
451  int count = this->callbacks.GetClassCount();
452 
453  this->classes.clear();
454  this->classes.reserve(count);
455 
456  bool filter_used = HasBit(this->callbacks.mode, PFM_USED);
457  bool filter_saved = HasBit(this->callbacks.mode, PFM_SAVED);
458  for (int i = 0; i < count; i++) {
459  if (this->callbacks.GetClassName(i) == INVALID_STRING_ID) continue;
460  if (filter_used && std::none_of(std::begin(this->callbacks.used), std::end(this->callbacks.used), [i](const PickerItem &item) { return item.class_index == i; })) continue;
461  if (filter_saved && std::none_of(std::begin(this->callbacks.saved), std::end(this->callbacks.saved), [i](const PickerItem &item) { return item.class_index == i; })) continue;
462  this->classes.emplace_back(i);
463  }
464 
465  this->classes.Filter(this->class_string_filter);
466  this->classes.RebuildDone();
467  this->classes.Sort();
468 
469  if (!this->has_class_picker) return;
470  this->GetScrollbar(WID_PW_CLASS_SCROLL)->SetCount(this->classes.size());
471 }
472 
473 void PickerWindow::EnsureSelectedClassIsValid()
474 {
475  int class_index = this->callbacks.GetSelectedClass();
476  if (std::binary_search(std::begin(this->classes), std::end(this->classes), class_index)) return;
477 
478  if (!this->classes.empty()) {
479  class_index = this->classes.front();
480  } else {
481  /* Classes can be empty if filters are enabled, find the first usable class. */
482  int count = this->callbacks.GetClassCount();
483  for (int i = 0; i < count; i++) {
484  if (this->callbacks.GetClassName(i) == INVALID_STRING_ID) continue;
485  class_index = i;
486  break;
487  }
488  }
489 
490  this->callbacks.SetSelectedClass(class_index);
491  this->types.ForceRebuild();
492 }
493 
494 void PickerWindow::EnsureSelectedClassIsVisible()
495 {
496  if (!this->has_class_picker) return;
497  if (this->classes.empty()) return;
498 
499  auto it = std::find(std::begin(this->classes), std::end(this->classes), this->callbacks.GetSelectedClass());
500  if (it == std::end(this->classes)) return;
501 
502  int pos = static_cast<int>(std::distance(std::begin(this->classes), it));
504 }
505 
506 void PickerWindow::RefreshUsedTypeList()
507 {
508  if (!this->has_type_picker) return;
509 
510  this->callbacks.used.clear();
511  this->callbacks.FillUsedItems(this->callbacks.used);
512  this->InvalidateData(PFI_TYPE);
513 }
514 
517 {
518  if (!this->types.NeedRebuild()) return;
519 
520  this->types.clear();
521 
522  bool show_all = HasBit(this->callbacks.mode, PFM_ALL);
523  bool filter_used = HasBit(this->callbacks.mode, PFM_USED);
524  bool filter_saved = HasBit(this->callbacks.mode, PFM_SAVED);
525  int cls_id = this->callbacks.GetSelectedClass();
526 
527  if (filter_used) {
528  /* Showing used items. May also be filtered by saved items. */
529  this->types.reserve(this->callbacks.used.size());
530  for (const PickerItem &item : this->callbacks.used) {
531  if (!show_all && item.class_index != cls_id) continue;
532  if (this->callbacks.GetTypeName(item.class_index, item.index) == INVALID_STRING_ID) continue;
533  this->types.emplace_back(item);
534  }
535  } else if (filter_saved) {
536  /* Showing only saved items. */
537  this->types.reserve(this->callbacks.saved.size());
538  for (const PickerItem &item : this->callbacks.saved) {
539  /* The used list may contain items that aren't currently loaded, skip these. */
540  if (item.class_index == -1) continue;
541  if (!show_all && item.class_index != cls_id) continue;
542  if (this->callbacks.GetTypeName(item.class_index, item.index) == INVALID_STRING_ID) continue;
543  this->types.emplace_back(item);
544  }
545  } else if (show_all) {
546  /* Reserve enough space for everything. */
547  int total = 0;
548  for (int class_index : this->classes) total += this->callbacks.GetTypeCount(class_index);
549  this->types.reserve(total);
550  /* Add types in all classes. */
551  for (int class_index : this->classes) {
552  int count = this->callbacks.GetTypeCount(class_index);
553  for (int i = 0; i < count; i++) {
554  if (this->callbacks.GetTypeName(class_index, i) == INVALID_STRING_ID) continue;
555  this->types.emplace_back(this->callbacks.GetPickerItem(class_index, i));
556  }
557  }
558  } else {
559  /* Add types in only the selected class. */
560  if (cls_id >= 0 && cls_id < this->callbacks.GetClassCount()) {
561  int count = this->callbacks.GetTypeCount(cls_id);
562  this->types.reserve(count);
563  for (int i = 0; i < count; i++) {
564  if (this->callbacks.GetTypeName(cls_id, i) == INVALID_STRING_ID) continue;
565  this->types.emplace_back(this->callbacks.GetPickerItem(cls_id, i));
566  }
567  }
568  }
569 
570  this->types.Filter(this->type_string_filter);
571  this->types.RebuildDone();
572  this->types.Sort();
573 
574  if (!this->has_type_picker) return;
575  this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX)->SetCount(static_cast<int>(this->types.size()));
576 }
577 
578 void PickerWindow::EnsureSelectedTypeIsValid()
579 {
580  int class_index = this->callbacks.GetSelectedClass();
581  int index = this->callbacks.GetSelectedType();
582  if (std::any_of(std::begin(this->types), std::end(this->types), [class_index, index](const auto &item) { return item.class_index == class_index && item.index == index; })) return;
583 
584  if (!this->types.empty()) {
585  class_index = this->types.front().class_index;
586  index = this->types.front().index;
587  } else {
588  /* Types can be empty if filters are enabled, find the first usable type. */
589  int count = this->callbacks.GetTypeCount(class_index);
590  for (int i = 0; i < count; i++) {
591  if (this->callbacks.GetTypeName(class_index, i) == INVALID_STRING_ID) continue;
592  index = i;
593  break;
594  }
595  }
596  this->callbacks.SetSelectedClass(class_index);
597  this->callbacks.SetSelectedType(index);
598 }
599 
600 void PickerWindow::EnsureSelectedTypeIsVisible()
601 {
602  if (!this->has_type_picker) return;
603  if (this->types.empty()) {
604  this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX)->SetClicked(-1);
605  return;
606  }
607 
608  int class_index = this->callbacks.GetSelectedClass();
609  int index = this->callbacks.GetSelectedType();
610 
611  auto it = std::find_if(std::begin(this->types), std::end(this->types), [class_index, index](const auto &item) { return item.class_index == class_index && item.index == index; });
612  if (it == std::end(this->types)) return;
613 
614  int pos = static_cast<int>(std::distance(std::begin(this->types), it));
615  this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX)->SetClicked(pos);
616 }
617 
619 std::unique_ptr<NWidgetBase> MakePickerClassWidgets()
620 {
621  static constexpr NWidgetPart picker_class_widgets[] = {
622  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_PW_CLASS_SEL),
624  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
625  NWidget(WWT_EDITBOX, COLOUR_DARK_GREEN, WID_PW_CLASS_FILTER), SetMinimalSize(144, 0), SetPadding(2), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
626  EndContainer(),
628  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
631  EndContainer(),
632  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_PW_CLASS_SCROLL),
633  EndContainer(),
634  EndContainer(),
635  EndContainer(),
636  };
637 
638  return MakeNWidgets(picker_class_widgets, nullptr);
639 }
640 
642 std::unique_ptr<NWidgetBase> MakePickerTypeWidgets()
643 {
644  static constexpr NWidgetPart picker_type_widgets[] = {
645  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_PW_TYPE_SEL),
647  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
648  NWidget(WWT_EDITBOX, COLOUR_DARK_GREEN, WID_PW_TYPE_FILTER), SetPadding(2), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
649  EndContainer(),
651  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_ALL), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_PICKER_MODE_ALL, STR_PICKER_MODE_ALL_TOOLTIP),
652  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_USED), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_PICKER_MODE_USED, STR_PICKER_MODE_USED_TOOLTIP),
653  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_SAVED), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_PICKER_MODE_SAVED, STR_PICKER_MODE_SAVED_TOOLTIP),
654  EndContainer(),
656  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_PW_TYPE_SCROLL),
657  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_PW_TYPE_MATRIX), SetPIP(0, 2, 0), SetPadding(WidgetDimensions::unscaled.picker),
659  EndContainer(),
660  EndContainer(),
661  EndContainer(),
662  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_PW_TYPE_SCROLL),
663  EndContainer(),
665  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
667  EndContainer(),
668  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN, WID_PW_TYPE_RESIZE),
669  EndContainer(),
670  EndContainer(),
671  EndContainer(),
672  };
673 
674  return MakeNWidgets(picker_type_widgets, nullptr);
675 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:738
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1183
GetColourGradient
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition: palette.cpp:314
Scrollbar::ScrollTowards
void ScrollTowards(size_type position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:843
sound_func.h
PickerWindow::has_type_picker
bool has_type_picker
Set if this window has a type picker 'component'.
Definition: picker_gui.h:171
PickerCallbacks::GetClassName
virtual StringID GetClassName(int id) const =0
Get the name of a class.
PickerCallbacks::type_last_filtering
Filtering type_last_filtering
Default filtering of PickerTypeList.
Definition: picker_gui.h:89
WID_PW_CLASS_SCROLL
@ WID_PW_CLASS_SCROLL
Scrollbar for list of classes.
Definition: picker_widget.h:20
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
PickerWindow::PREVIEW_HEIGHT
static const int PREVIEW_HEIGHT
Height of each preview button.
Definition: picker_gui.h:164
_type_sorter_funcs
static const std::initializer_list< PickerTypeList::SortFunction *const > _type_sorter_funcs
Sort functions of the PickerTypeList.
Definition: picker_gui.cpp:155
PickerWindow::PREVIEW_WIDTH
static const int PREVIEW_WIDTH
Width of each preview button.
Definition: picker_gui.h:163
querystring_gui.h
PickerWindow::PFM_ALL
@ PFM_ALL
Show all classes.
Definition: picker_gui.h:151
PickerFilterData::callbacks
const PickerCallbacks * callbacks
Callbacks for filter functions to access to callbacks.
Definition: picker_gui.h:142
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:422
PickerWindow::PFM_USED
@ PFM_USED
Show used types.
Definition: picker_gui.h:152
PickerCallbacks
Class for PickerClassWindow to collect information and retain state.
Definition: picker_gui.h:37
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:330
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
WID_PW_CLASS_LIST
@ WID_PW_CLASS_LIST
List of classes.
Definition: picker_widget.h:19
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
PickerSaveConfig
static void PickerSaveConfig(IniFile &ini, const PickerCallbacks &callbacks)
Save favourites of a picker to config.
Definition: picker_gui.cpp:94
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
widget_type.h
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:599
IniItem
A single "line" in an ini file.
Definition: ini_type.h:23
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1140
sound_type.h
TypeIDSorter
static bool TypeIDSorter(PickerItem const &a, PickerItem const &b)
Sort types by id.
Definition: picker_gui.cpp:138
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
PickerWindow::PFI_POSITION
@ PFI_POSITION
Update scroll positions.
Definition: picker_gui.h:159
IniGroup
A group within an ini file.
Definition: ini_type.h:34
PickerCallbacks::GetTypeCount
virtual int GetTypeCount(int cls_id) const =0
Get the number of types in a class.
window_type.h
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
PickerCallbacks::FillUsedItems
virtual void FillUsedItems(std::set< PickerItem > &items)=0
Fill a set with all items that are used by the current player.
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
PickerCallbacks::type_last_sorting
Listing type_last_sorting
Default sorting of PickerTypeList.
Definition: picker_gui.h:88
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1216
PickerWindow::PCWHK_FOCUS_FILTER_BOX
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition: picker_gui.h:185
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:301
WID_PW_MODE_ALL
@ WID_PW_MODE_ALL
Toggle "Show all" filter mode.
Definition: picker_widget.h:24
PickerCallbacks::GetSelectedClass
virtual int GetSelectedClass() const =0
Get the index of the selected class.
zoom_func.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2394
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:56
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:484
IniGroup::items
std::list< IniItem > items
all items in the group
Definition: ini_type.h:35
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
ConvertHexToBytes
bool ConvertHexToBytes(std::string_view hex, std::span< uint8_t > bytes)
Convert a hex-string to a byte-array, while validating it was actually hex.
Definition: string.cpp:711
WID_PW_MODE_USED
@ WID_PW_MODE_USED
Toggle showing only used types.
Definition: picker_widget.h:25
PickerCallbacks::SetSelectedType
virtual void SetSelectedType(int id) const =0
Set the selected type.
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition: widget_type.h:80
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
PickerCallbacks::GetClassTooltip
virtual StringID GetClassTooltip() const =0
Get the tooltip string for the class list.
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1077
GUIList::SetFilterFuncs
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
Definition: sortlist_type.h:369
Window::nested_focus
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition: window_gui.h:322
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:391
PickerCallbacks::GetSelectedType
virtual int GetSelectedType() const =0
Get the selected type.
IniGroup::Clear
void Clear()
Clear all items in the group.
Definition: ini_load.cpp:98
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
PickerCallbacks::DrawType
virtual void DrawType(int x, int y, int cls_id, int id) const =0
Draw preview image of an item.
PickerCallbacks::HasClassChoice
virtual bool HasClassChoice() const =0
Are there multiple classes to chose from?
WindowDesc
High level window description.
Definition: window_gui.h:162
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
picker_gui.h
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
window_gui.h
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:526
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1230
PickerCallbacks::mode
uint8_t mode
Bitmask of PickerFilterModes.
Definition: picker_gui.h:92
_class_filter_funcs
static const std::initializer_list< PickerClassList::FilterFunction *const > _class_filter_funcs
Filter functions of the PickerClassList.
Definition: picker_gui.cpp:154
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1128
PickerCallbacks::class_last_filtering
Filtering class_last_filtering
Default filtering of PickerClassList.
Definition: picker_gui.h:86
PickerWindow::classes
PickerClassList classes
List of classes.
Definition: picker_gui.h:194
PickerWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: picker_gui.cpp:408
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:364
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:614
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
WID_PW_TYPE_SEL
@ WID_PW_TYPE_SEL
Stack to hide the type picker.
Definition: picker_widget.h:22
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1286
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:346
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
WID_PW_TYPE_MATRIX
@ WID_PW_TYPE_MATRIX
Matrix with items.
Definition: picker_widget.h:27
PickerWindow::BuildPickerClassList
void BuildPickerClassList()
Builds the filter list of classes.
Definition: picker_gui.cpp:447
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:739
PickerWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: picker_gui.cpp:320
PickerWindow::PFI_VALIDATE
@ PFI_VALIDATE
Validate selected item.
Definition: picker_gui.h:160
PickerWindowBase::Close
void Close([[maybe_unused]] int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:3511
PickerWindow::BuildPickerTypeList
void BuildPickerTypeList()
Builds the filter list of types.
Definition: picker_gui.cpp:516
PickerCallbacks::GetClassCount
virtual int GetClassCount() const =0
Get the number of classes.
WID_PW_TYPE_RESIZE
@ WID_PW_TYPE_RESIZE
Type resize handle.
Definition: picker_widget.h:31
PickerWindow::PREVIEW_LEFT
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition: picker_gui.h:165
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
safeguards.h
sortlist_type.h
PickerCallbacks::IsTypeAvailable
virtual bool IsTypeAvailable(int cls_id, int id) const =0
Test if an item is currently buildable.
PickerCallbacks::GetTypeName
virtual StringID GetTypeName(int cls_id, int id) const =0
Get the item of a type.
PickerCallbacks::class_last_sorting
Listing class_last_sorting
Default sorting of PickerClassList.
Definition: picker_gui.h:85
MakePickerTypeWidgets
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Definition: picker_gui.cpp:642
PickerWindow::PFI_CLASS
@ PFI_CLASS
Refresh the class list.
Definition: picker_gui.h:157
PickerWindow::class_editbox
QueryString class_editbox
Filter editbox.
Definition: picker_gui.h:196
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:988
IniLoadFile::GetOrCreateGroup
IniGroup & GetOrCreateGroup(std::string_view name)
Get the group with the given name, and if it doesn't exist create a new group.
Definition: ini_load.cpp:147
settings_type.h
WID_PW_TYPE_FILTER
@ WID_PW_TYPE_FILTER
Text filter.
Definition: picker_widget.h:23
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:419
PickerCallbacks::IsActive
virtual bool IsActive() const =0
Should picker class/type selection be enabled?
MakeNWidgets
std::unique_ptr< NWidgetBase > MakeNWidgets(std::span< const NWidgetPart > nwid_parts, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:3210
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:305
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:486
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3148
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:450
PickerFilterData
Definition: picker_gui.h:141
PickerCallbacks::GetPickerItem
virtual PickerItem GetPickerItem(int cls_id, int id) const =0
Get data about an item.
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1548
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:390
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
PickerCallbacks::saved
std::set< PickerItem > saved
Set of saved favourite items.
Definition: picker_gui.h:95
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:399
string_func.h
WID_PW_TYPE_SCROLL
@ WID_PW_TYPE_SCROLL
Scrollbar for the matrix.
Definition: picker_widget.h:29
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
PickerLoadConfig
static void PickerLoadConfig(const IniFile &ini, PickerCallbacks &callbacks)
Load favourites of a picker from config.
Definition: picker_gui.cpp:60
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:242
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1723
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
TypeTagNameFilter
static bool TypeTagNameFilter(PickerItem const *item, PickerFilterData &filter)
Filter types by class name.
Definition: picker_gui.cpp:146
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
PickerCallbacks::SetSelectedClass
virtual void SetSelectedClass(int id) const =0
Set the selected class.
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1262
WID_PW_MODE_SAVED
@ WID_PW_MODE_SAVED
Toggle showing only saved types.
Definition: picker_widget.h:26
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
_class_sorter_funcs
static const std::initializer_list< PickerClassList::SortFunction *const > _class_sorter_funcs
Sort functions of the PickerClassList.
Definition: picker_gui.cpp:153
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:150
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:782
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:319
EventState
EventState
State of handling an event.
Definition: window_type.h:737
IniLoadFile::GetGroup
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
Definition: ini_load.cpp:119
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
PickerWindowBase
Base class for windows opened from a toolbar.
Definition: window_gui.h:989
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
NWidgetCore::index
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:394
PickerCallbacks::UpdateSavedItems
virtual std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src)=0
Update link between grfid/localidx and class_index/index in saved items.
WID_PW_TYPE_NAME
@ WID_PW_TYPE_NAME
Name of selected item.
Definition: picker_widget.h:30
window_func.h
IniItem::name
std::string name
The name of this item.
Definition: ini_type.h:24
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:355
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:249
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:77
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
WID_PW_CLASS_SEL
@ WID_PW_CLASS_SEL
Stack to hide the class picker.
Definition: picker_widget.h:17
stringfilter_type.h
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1139
PickerCallbacks::ini_group
const std::string ini_group
Ini Group for saving favourites.
Definition: picker_gui.h:91
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:409
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:657
PickerWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: picker_gui.cpp:236
ClassTagNameFilter
static bool ClassTagNameFilter(int const *item, PickerFilterData &filter)
Filter classes by class name.
Definition: picker_gui.cpp:130
gui.h
PickerWindow::PREVIEW_BOTTOM
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition: picker_gui.h:166
ClassIDSorter
static bool ClassIDSorter(int const &a, int const &b)
Sort classes by id.
Definition: picker_gui.cpp:124
_type_filter_funcs
static const std::initializer_list< PickerTypeList::FilterFunction *const > _type_filter_funcs
Filter functions of the PickerTypeList.
Definition: picker_gui.cpp:156
MakePickerClassWidgets
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
Definition: picker_gui.cpp:619
Window
Data structure for an opened window.
Definition: window_gui.h:276
IniGroup::CreateItem
IniItem & CreateItem(std::string_view name)
Create an item with the given name.
Definition: ini_load.cpp:81
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:483
PickerWindow::has_class_picker
bool has_class_picker
Set if this window has a class picker 'component'.
Definition: picker_gui.h:170
PickerCallbacks::used
std::set< PickerItem > used
Set of items used in the current game by the current company.
Definition: picker_gui.h:94
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1204
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1151
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
PickerItem
Definition: picker_gui.h:23
PickerWindow::type_editbox
QueryString type_editbox
Filter editbox.
Definition: picker_gui.h:204
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
picker_widget.h
WID_PW_CLASS_FILTER
@ WID_PW_CLASS_FILTER
Editbox filter.
Definition: picker_widget.h:18
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:270
WID_PW_TYPE_ITEM
@ WID_PW_TYPE_ITEM
A single item.
Definition: picker_widget.h:28
ini_type.h
PickerWindow::PFM_SAVED
@ PFM_SAVED
Show saved types.
Definition: picker_gui.h:153
GUIList::SetFiltering
void SetFiltering(Filtering f)
Import filter conditions.
Definition: sortlist_type.h:204
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GUIList::SetSortFuncs
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
Definition: sortlist_type.h:297
PickerCallbacks::GetTypeTooltip
virtual StringID GetTypeTooltip() const =0
Get the tooltip string for the type grid.
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:157
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:152
hotkeys.h
PickerWindow::PFI_TYPE
@ PFI_TYPE
Refresh the type list.
Definition: picker_gui.h:158
PickerWindow::types
PickerTypeList types
List of types.
Definition: picker_gui.h:202
backup_type.hpp
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103