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

Method OnClick

src/company_gui.cpp:912–987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

910 }
911
912 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
913 {
914 switch (widget) {
915 /* Livery Class buttons */
916 case WID_SCL_CLASS_GENERAL:
917 case WID_SCL_CLASS_RAIL:
918 case WID_SCL_CLASS_ROAD:
919 case WID_SCL_CLASS_SHIP:
920 case WID_SCL_CLASS_AIRCRAFT:
921 case WID_SCL_GROUPS_RAIL:
922 case WID_SCL_GROUPS_ROAD:
923 case WID_SCL_GROUPS_SHIP:
924 case WID_SCL_GROUPS_AIRCRAFT:
925 this->RaiseWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
926 this->livery_class = (LiveryClass)(widget - WID_SCL_CLASS_GENERAL);
927 this->LowerWidget(WID_SCL_CLASS_GENERAL + this->livery_class);
928
929 /* Select the first item in the list */
930 if (this->livery_class < LC_GROUP_RAIL) {
931 this->sel = 0;
932 for (LiveryScheme scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
933 if (_livery_class[scheme] == this->livery_class && HasBit(_loaded_newgrf_features.used_liveries, scheme)) {
934 this->sel = 1 << scheme;
935 break;
936 }
937 }
938 } else {
939 this->sel = GroupID::Invalid().base();
940 this->groups.ForceRebuild();
941 this->BuildGroupList(this->window_number);
942
943 if (!this->groups.empty()) {
944 this->sel = this->groups[0].group->index.base();
945 }
946 }
947
948 this->SetRows();
949 this->SetDirty();
950 break;
951
952 case WID_SCL_PRI_COL_DROPDOWN: // First colour dropdown
953 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN);
954 break;
955
956 case WID_SCL_SEC_COL_DROPDOWN: // Second colour dropdown
957 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN);
958 break;
959
960 case WID_SCL_MATRIX: {
961 if (this->livery_class < LC_GROUP_RAIL) {
962 uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
963 if (row >= this->rows) return;
964
965 LiveryScheme j = (LiveryScheme)row;
966
967 for (LiveryScheme scheme = LS_BEGIN; scheme <= j && scheme < LS_END; scheme++) {
968 if (_livery_class[scheme] != this->livery_class || !HasBit(_loaded_newgrf_features.used_liveries, scheme)) j++;
969 }

Callers 1

OnInvalidateDataMethod · 0.95

Calls 14

BuildGroupListMethod · 0.95
SetRowsMethod · 0.95
HasBitFunction · 0.85
InvalidFunction · 0.85
ToggleBitFunction · 0.85
RaiseWidgetMethod · 0.80
LowerWidgetMethod · 0.80
ForceRebuildMethod · 0.80
endFunction · 0.50
baseMethod · 0.45

Tested by

no test coverage detected