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

Method OnClick

src/industry_gui.cpp:630–692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628 }
629
630 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
631 {
632 switch (widget) {
633 case WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET: {
634 assert(_game_mode == GM_EDITOR);
635 this->HandleButtonClick(WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET);
636 ShowQuery(
637 GetEncodedString(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION),
638 GetEncodedString(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY),
639 nullptr, AskManyRandomIndustriesCallback);
640 break;
641 }
642
643 case WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET: {
644 assert(_game_mode == GM_EDITOR);
645 this->HandleButtonClick(WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET);
646 ShowQuery(
647 GetEncodedString(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION),
648 GetEncodedString(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY),
649 nullptr, AskRemoveAllIndustriesCallback);
650 break;
651 }
652
653 case WID_DPI_MATRIX_WIDGET: {
654 auto it = this->vscroll->GetScrolledItemFromWidget(this->list, pt.y, this, WID_DPI_MATRIX_WIDGET);
655 if (it != this->list.end()) { // Is it within the boundaries of available data?
656 this->selected_type = *it;
657 this->UpdateAvailability();
658
659 const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
660
661 this->SetDirty();
662
663 if (_thd.GetCallbackWnd() == this &&
664 ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || !this->enabled)) {
665 /* Reset the button state if going to prospecting or "build many industries" */
666 this->RaiseButtons();
667 ResetObjectToPlace();
668 }
669
670 this->SetButtons();
671 if (this->enabled && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
672 }
673 break;
674 }
675
676 case WID_DPI_DISPLAY_WIDGET:
677 if (this->selected_type != IT_INVALID) ShowIndustryCargoesWindow(this->selected_type);
678 break;
679
680 case WID_DPI_FUND_WIDGET: {
681 if (this->selected_type != IT_INVALID) {
682 if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
683 Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, TileIndex{}, this->selected_type, 0, false, InteractiveRandom());
684 this->HandleButtonClick(WID_DPI_FUND_WIDGET);
685 } else {
686 HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
687 }

Callers

nothing calls this directly

Calls 15

UpdateAvailabilityMethod · 0.95
SetButtonsMethod · 0.95
ShowQueryFunction · 0.85
GetIndustrySpecFunction · 0.85
ResetObjectToPlaceFunction · 0.85
InteractiveRandomFunction · 0.85
HandlePlacePushButtonFunction · 0.85
HandleButtonClickMethod · 0.80
GetCallbackWndMethod · 0.80
RaiseButtonsMethod · 0.80

Tested by

no test coverage detected