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

Method EnsureSelectedTypeIsValid

src/picker_gui.cpp:702–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

700}
701
702void PickerWindow::EnsureSelectedTypeIsValid()
703{
704 int class_index = this->callbacks.GetSelectedClass();
705 int index = this->callbacks.GetSelectedType();
706 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;
707
708 if (!this->types.empty()) {
709 class_index = this->types.front().class_index;
710 index = this->types.front().index;
711 } else {
712 /* Types can be empty if filters are enabled, find the first usable type. */
713 int count = this->callbacks.GetTypeCount(class_index);
714 for (int i = 0; i < count; i++) {
715 if (this->callbacks.GetTypeName(class_index, i) == INVALID_STRING_ID) continue;
716 index = i;
717 break;
718 }
719 }
720 this->callbacks.SetSelectedClass(class_index);
721 this->callbacks.SetSelectedType(index);
722}
723
724void PickerWindow::EnsureSelectedTypeIsVisible()
725{

Callers 1

OnInvalidateDataMethod · 0.95

Calls 9

beginFunction · 0.50
endFunction · 0.50
GetSelectedClassMethod · 0.45
GetSelectedTypeMethod · 0.45
emptyMethod · 0.45
GetTypeCountMethod · 0.45
GetTypeNameMethod · 0.45
SetSelectedClassMethod · 0.45
SetSelectedTypeMethod · 0.45

Tested by

no test coverage detected