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

Method OnClick

src/group_gui.cpp:737–912  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

735 }
736
737 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
738 {
739 switch (widget) {
740 case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
741 this->vehgroups.ToggleSortOrder();
742 this->SetDirty();
743 break;
744
745 case WID_GL_GROUP_BY_DROPDOWN: // Select grouping option dropdown menu
746 ShowDropDownMenu(this, this->vehicle_group_by_names, this->grouping, WID_GL_GROUP_BY_DROPDOWN, 0, 0);
747 return;
748
749 case WID_GL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
750 ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_GL_SORT_BY_DROPDOWN, 0, (this->vli.vtype == VEH_TRAIN || this->vli.vtype == VEH_ROAD) ? 0 : (1 << 10));
751 return;
752
753 case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
754 ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
755 break;
756
757 case WID_GL_ALL_VEHICLES: // All vehicles button
758 if (!IsAllGroupID(this->vli.ToGroupID())) {
759 this->vli.SetIndex(ALL_GROUP);
760 this->vehgroups.ForceRebuild();
761 this->SetDirty();
762 }
763 break;
764
765 case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles button
766 if (!IsDefaultGroupID(this->vli.ToGroupID())) {
767 this->vli.SetIndex(DEFAULT_GROUP);
768 this->vehgroups.ForceRebuild();
769 this->SetDirty();
770 }
771 break;
772
773 case WID_GL_LIST_GROUP: { // Matrix Group
774 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
775 if (it == this->groups.end()) return;
776
777 if (it->group->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent)) {
778 /* The group has children, check if the user clicked the fold / unfold button. */
779 bool rtl = _current_text_dir == TD_RTL;
780 Rect r = this->GetWidget<NWidgetCore>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect, RectPadding::zero);
781 r = r.Indent(it->indent * WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(this->column_size[VGC_FOLD].width, rtl);
782 if (click_count > 1 || r.Contains(pt)) {
783
784 GroupID g = this->vli.ToGroupID();
785 if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
786 do {
787 g = Group::Get(g)->parent;
788 if (g == it->group->index) {
789 this->vli.SetIndex(g);
790 break;
791 }
792 } while (g != GroupID::Invalid());
793 }
794

Callers

nothing calls this directly

Calls 15

SelectGroupMethod · 0.95
ShowRenameGroupWindowMethod · 0.95
ShowDropDownMenuFunction · 0.85
ShowDropDownListFunction · 0.85
IsAllGroupIDFunction · 0.85
IsDefaultGroupIDFunction · 0.85
InvalidFunction · 0.85
SetObjectToPlaceWndFunction · 0.85
VehicleClickedFunction · 0.85
NOT_REACHEDFunction · 0.85
ShowOrdersWindowFunction · 0.85
SetMouseCursorVehicleFunction · 0.85

Tested by

no test coverage detected