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

Method OnDropdownSelect

src/station_gui.cpp:672–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

670 }
671
672 void OnDropdownSelect(WidgetID widget, int index, int) override
673 {
674 if (widget == WID_STL_SORTDROPBTN) {
675 if (this->stations.SortType() != index) {
676 this->stations.SetSortType(index);
677
678 /* Display the current sort variant */
679 this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->SetString(CompanyStationsWindow::sorter_names[this->stations.SortType()]);
680
681 this->SetDirty();
682 }
683 }
684
685 if (widget == WID_STL_CARGODROPDOWN) {
686 FilterState oldstate = this->filter;
687
688 if (index >= 0 && index < NUM_CARGO) {
689 if (_ctrl_pressed) {
690 ToggleBit(this->filter.cargoes, index);
691 } else {
692 this->filter.cargoes = 1ULL << index;
693 this->filter.include_no_rating = false;
694 }
695 } else if (index == CargoFilterCriteria::CF_NO_RATING) {
696 if (_ctrl_pressed) {
697 this->filter.include_no_rating = !this->filter.include_no_rating;
698 } else {
699 this->filter.include_no_rating = true;
700 this->filter.cargoes = 0;
701 }
702 } else if (index == CargoFilterCriteria::CF_SELECT_ALL) {
703 this->filter.cargoes = _cargo_mask;
704 this->filter.include_no_rating = true;
705 } else if (index == CargoFilterCriteria::CF_EXPAND_LIST) {
706 this->filter_expanded = true;
707 ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
708 return;
709 }
710
711 if (oldstate.cargoes != this->filter.cargoes || oldstate.include_no_rating != this->filter.include_no_rating) {
712 this->stations.ForceRebuild();
713 this->SetDirty();
714
715 /* Only refresh the list if it's changed. */
716 if (_ctrl_pressed) ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
717 }
718
719 /* Always close the list if ctrl is not pressed. */
720 if (!_ctrl_pressed) this->CloseChildWindows(WC_DROPDOWN_MENU);
721 }
722 }
723
724 void OnGameTick() override
725 {

Callers

nothing calls this directly

Calls 9

ToggleBitFunction · 0.85
ReplaceDropDownListFunction · 0.85
SortTypeMethod · 0.80
SetSortTypeMethod · 0.80
ForceRebuildMethod · 0.80
CloseChildWindowsMethod · 0.80
SetStringMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected