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

Method EnsureSelectedClassIsValid

src/picker_gui.cpp:597–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595}
596
597void PickerWindow::EnsureSelectedClassIsValid()
598{
599 int class_index = this->callbacks.GetSelectedClass();
600 if (std::binary_search(std::begin(this->classes), std::end(this->classes), class_index)) return;
601
602 if (!this->classes.empty()) {
603 class_index = this->classes.front();
604 } else {
605 /* Classes can be empty if filters are enabled, find the first usable class. */
606 int count = this->callbacks.GetClassCount();
607 for (int i = 0; i < count; i++) {
608 if (this->callbacks.GetClassName(i) == INVALID_STRING_ID) continue;
609 class_index = i;
610 break;
611 }
612 }
613
614 this->callbacks.SetSelectedClass(class_index);
615 this->types.ForceRebuild();
616}
617
618void PickerWindow::EnsureSelectedClassIsVisible()
619{

Callers 1

OnInvalidateDataMethod · 0.95

Calls 8

ForceRebuildMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
GetSelectedClassMethod · 0.45
emptyMethod · 0.45
GetClassCountMethod · 0.45
GetClassNameMethod · 0.45
SetSelectedClassMethod · 0.45

Tested by

no test coverage detected