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

Method OnClick

src/script/script_gui.cpp:999–1066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997 }
998
999 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1000 {
1001 /* Also called for hotkeys, so check for disabledness */
1002 if (this->IsWidgetDisabled(widget)) return;
1003
1004 /* Check which button is clicked */
1005 if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) {
1006 this->ChangeToScript(static_cast<CompanyID>(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed);
1007 }
1008
1009 switch (widget) {
1010 case WID_SCRD_SCRIPT_GAME:
1011 this->ChangeToScript(OWNER_DEITY, _ctrl_pressed);
1012 break;
1013
1014 case WID_SCRD_RELOAD_TOGGLE:
1015 if (this->filter.script_debug_company == OWNER_DEITY) break;
1016 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1017 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, this->filter.script_debug_company, CRR_MANUAL, INVALID_CLIENT_ID);
1018 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, this->filter.script_debug_company, CRR_NONE, INVALID_CLIENT_ID);
1019 break;
1020
1021 case WID_SCRD_SETTINGS:
1022 ShowScriptSettingsWindow(this->filter.script_debug_company);
1023 break;
1024
1025 case WID_SCRD_BREAK_STR_ON_OFF_BTN:
1026 this->filter.break_check_enabled = !this->filter.break_check_enabled;
1027 this->InvalidateData(-1);
1028 break;
1029
1030 case WID_SCRD_MATCH_CASE_BTN:
1031 this->filter.case_sensitive_break_check = !this->filter.case_sensitive_break_check;
1032 this->InvalidateData(-1);
1033 break;
1034
1035 case WID_SCRD_CONTINUE_BTN:
1036 /* Unpause current AI / game script and mark the corresponding script button dirty. */
1037 if (!this->IsDead()) {
1038 if (this->filter.script_debug_company == OWNER_DEITY) {
1039 Game::Unpause();
1040 } else {
1041 AI::Unpause(this->filter.script_debug_company);
1042 }
1043 }
1044
1045 /* If the last AI/Game Script is unpaused, unpause the game too. */
1046 if (_pause_mode.Test(PauseMode::Normal)) {
1047 bool all_unpaused = !Game::IsPaused();
1048 if (all_unpaused) {
1049 for (const Company *c : Company::Iterate()) {
1050 if (c->is_ai && AI::IsPaused(c->index)) {
1051 all_unpaused = false;
1052 break;
1053 }
1054 }
1055 if (all_unpaused) {
1056 /* All scripts have been unpaused => unpause the game. */

Callers

nothing calls this directly

Calls 7

ChangeToScriptMethod · 0.95
IsDeadMethod · 0.95
IsInsideMMFunction · 0.85
ShowScriptSettingsWindowFunction · 0.85
IsWidgetDisabledMethod · 0.80
TestMethod · 0.80
InvalidateDataMethod · 0.45

Tested by

no test coverage detected