MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildPickerClassList

Method BuildPickerClassList

src/picker_gui.cpp:571–595  ·  view source on GitHub ↗

Builds the filter list of classes. */

Source from the content-addressed store, hash-verified

569
570/** Builds the filter list of classes. */
571void PickerWindow::BuildPickerClassList()
572{
573 if (!this->classes.NeedRebuild()) return;
574
575 int count = this->callbacks.GetClassCount();
576
577 this->classes.clear();
578 this->classes.reserve(count);
579
580 bool filter_used = HasBit(this->callbacks.mode, PFM_USED);
581 bool filter_saved = HasBit(this->callbacks.mode, PFM_SAVED);
582 for (int i = 0; i < count; i++) {
583 if (this->callbacks.GetClassName(i) == INVALID_STRING_ID) continue;
584 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;
585 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;
586 this->classes.emplace_back(i);
587 }
588
589 this->classes.Filter(this->class_string_filter);
590 this->classes.RebuildDone();
591 this->classes.Sort();
592
593 if (!this->has_class_picker) return;
594 this->GetScrollbar(WID_PW_CLASS_SCROLL)->SetCount(this->classes.size());
595}
596
597void PickerWindow::EnsureSelectedClassIsValid()
598{

Callers 1

OnInvalidateDataMethod · 0.95

Calls 14

HasBitFunction · 0.85
NeedRebuildMethod · 0.80
reserveMethod · 0.80
RebuildDoneMethod · 0.80
GetScrollbarMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
GetClassCountMethod · 0.45
clearMethod · 0.45
GetClassNameMethod · 0.45
FilterMethod · 0.45
SortMethod · 0.45

Tested by

no test coverage detected