OpenTTD Source: src/script/script_gui.cpp Source File

OpenTTD Source 14.0-beta3

script_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../table/sprites.h"
12 #include "../error.h"
13 #include "../settings_gui.h"
14 #include "../querystring_gui.h"
15 #include "../stringfilter_type.h"
16 #include "../company_base.h"
17 #include "../company_gui.h"
18 #include "../window_func.h"
19 #include "../network/network.h"
20 #include "../widgets/dropdown_func.h"
21 #include "../hotkeys.h"
22 #include "../company_cmd.h"
23 #include "../misc_cmd.h"
24 #include "../timer/timer.h"
25 #include "../timer/timer_window.h"
26
27 #include "script_gui.h"
28 #include "script_log.hpp"
29 #include "script_scanner.hpp"
30 #include "script_config.hpp"
31 #include "../ai/ai.hpp"
32 #include "../ai/ai_config.hpp"
33 #include "../ai/ai_info.hpp"
34 #include "../ai/ai_instance.hpp"
35 #include "../game/game.hpp"
36 #include "../game/game_config.hpp"
37 #include "../game/game_info.hpp"
38 #include "../game/game_instance.hpp"
39 #include "table/strings.h"
40
41 #include "../safeguards.h"
42
43
44 static ScriptConfig *GetConfig(CompanyID slot)
45 {
46 if (slot == OWNER_DEITY) return GameConfig::GetConfig();
47 return AIConfig::GetConfig(slot);
48 }
49
53 struct ScriptListWindow : public Window {
54 const ScriptInfoList *info_list;
55 int selected;
56 CompanyID slot;
57 int line_height;
58 Scrollbar *vscroll;
59 bool show_all;
60
67 ScriptListWindow(WindowDesc *desc, CompanyID slot, bool show_all) : Window(desc),
68 slot(slot), show_all(show_all)
69 {
70 if (slot == OWNER_DEITY) {
71 this->info_list = this->show_all ? Game::GetInfoList() : Game::GetUniqueInfoList();
72 } else {
73 this->info_list = this->show_all ? AI::GetInfoList() : AI::GetUniqueInfoList();
74 }
75
76 this->CreateNestedTree();
77 this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR);
78 this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
79
80 this->vscroll->SetCount(this->info_list->size() + 1);
81
82 /* Try if we can find the currently selected AI */
83 this->selected = -1;
84 if (GetConfig(slot)->HasScript()) {
85 ScriptInfo *info = GetConfig(slot)->GetInfo();
86 int i = 0;
87 for (const auto &item : *this->info_list) {
88 if (item.second == info) {
89 this->selected = i;
90 break;
91 }
92
93 i++;
94 }
95 }
96 }
97
98 void SetStringParameters(WidgetID widget) const override
99 {
100 if (widget != WID_SCRL_CAPTION) return;
101
102 SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
103 }
104
105 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
106 {
107 if (widget != WID_SCRL_LIST) return;
108
109 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
110
111 resize->width = 1;
112 resize->height = this->line_height;
113 size->height = 5 * this->line_height;
114 }
115
116 void DrawWidget(const Rect &r, WidgetID widget) const override
117 {
118 switch (widget) {
119 case WID_SCRL_LIST: {
120 /* Draw a list of all available Scripts. */
121 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
122 /* First AI in the list is hardcoded to random */
123 if (this->vscroll->IsVisible(0)) {
124 DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
125 tr.top += this->line_height;
126 }
127 StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
128 int i = 0;
129 for (const auto &item : *this->info_list) {
130 i++;
131 if (this->vscroll->IsVisible(i)) {
132 SetDParamStr(0, item.second->GetName());
133 SetDParam(1, item.second->GetVersion());
134 DrawString(tr, str, (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
135 tr.top += this->line_height;
136 }
137 }
138 break;
139 }
140 case WID_SCRL_INFO_BG: {
141 ScriptInfo *selected_info = nullptr;
142 int i = 0;
143 for (const auto &item : *this->info_list) {
144 i++;
145 if (this->selected == i - 1) selected_info = static_cast<ScriptInfo *>(item.second);
146 }
147 /* Some info about the currently selected Script. */
148 if (selected_info != nullptr) {
149 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
150 SetDParamStr(0, selected_info->GetAuthor());
151 DrawString(tr, STR_AI_LIST_AUTHOR);
152 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
153 SetDParam(0, selected_info->GetVersion());
154 DrawString(tr, STR_AI_LIST_VERSION);
155 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
156 if (!selected_info->GetURL().empty()) {
157 SetDParamStr(0, selected_info->GetURL());
158 DrawString(tr, STR_AI_LIST_URL);
159 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
160 }
161 SetDParamStr(0, selected_info->GetDescription());
162 DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_WHITE);
163 }
164 break;
165 }
166 }
167 }
168
172 void ChangeScript()
173 {
174 if (this->selected == -1) {
175 GetConfig(slot)->Change(std::nullopt);
176 } else {
177 ScriptInfoList::const_iterator it = this->info_list->cbegin();
178 std::advance(it, this->selected);
179 GetConfig(slot)->Change(it->second->GetName(), it->second->GetVersion());
180 }
181 InvalidateWindowData(WC_GAME_OPTIONS, slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI);
182 InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
183 CloseWindowByClass(WC_QUERY_STRING);
184 InvalidateWindowClassesData(WC_TEXTFILE);
185 }
186
187 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
188 {
189 switch (widget) {
190 case WID_SCRL_LIST: { // Select one of the Scripts
191 int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCRL_LIST) - 1;
192 if (sel < (int)this->info_list->size()) {
193 this->selected = sel;
194 this->SetDirty();
195 if (click_count > 1) {
196 this->ChangeScript();
197 this->Close();
198 }
199 }
200 break;
201 }
202
203 case WID_SCRL_ACCEPT: {
204 this->ChangeScript();
205 this->Close();
206 break;
207 }
208
209 case WID_SCRL_CANCEL:
210 this->Close();
211 break;
212 }
213 }
214
215 void OnResize() override
216 {
217 this->vscroll->SetCapacityFromWidget(this, WID_SCRL_LIST);
218 }
219
225 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
226 {
227 if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
228 this->Close();
229 return;
230 }
231
232 if (!gui_scope) return;
233
234 this->vscroll->SetCount(this->info_list->size() + 1);
235
236 /* selected goes from -1 .. length of ai list - 1. */
237 this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
238 }
239 };
240
242 static constexpr NWidgetPart _nested_script_list_widgets[] = {
243 NWidget(NWID_HORIZONTAL),
244 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
245 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
246 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
247 EndContainer(),
248 NWidget(NWID_HORIZONTAL),
249 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_SCRL_LIST), SetMinimalSize(188, 112), SetFill(1, 1), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP), SetScrollbar(WID_SCRL_SCROLLBAR),
250 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRL_SCROLLBAR),
251 EndContainer(),
252 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_SCRL_INFO_BG), SetMinimalTextLines(8, WidgetDimensions::unscaled.framerect.Vertical() + WidgetDimensions::unscaled.vsep_normal * 3), SetResize(1, 0),
253 EndContainer(),
254 NWidget(NWID_HORIZONTAL),
255 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
256 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
257 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
258 EndContainer(),
259 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
260 EndContainer(),
261 };
262
264 static WindowDesc _script_list_desc(__FILE__, __LINE__,
265 WDP_CENTER, "settings_script_list", 200, 234,
266 WC_SCRIPT_LIST, WC_NONE,
267 0,
268 std::begin(_nested_script_list_widgets), std::end(_nested_script_list_widgets)
269 );
270
276 void ShowScriptListWindow(CompanyID slot, bool show_all)
277 {
278 CloseWindowByClass(WC_SCRIPT_LIST);
279 new ScriptListWindow(&_script_list_desc, slot, show_all);
280 }
281
282
286 struct ScriptSettingsWindow : public Window {
287 CompanyID slot;
288 ScriptConfig *script_config;
289 int clicked_button;
290 bool clicked_increase;
291 bool clicked_dropdown;
292 bool closing_dropdown;
293 int clicked_row;
294 int line_height;
295 Scrollbar *vscroll;
296 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
297 VisibleSettingsList visible_settings;
298
304 ScriptSettingsWindow(WindowDesc *desc, CompanyID slot) : Window(desc),
305 slot(slot),
306 clicked_button(-1),
307 clicked_dropdown(false),
308 closing_dropdown(false)
309 {
310 this->script_config = GetConfig(slot);
311
312 this->CreateNestedTree();
313 this->vscroll = this->GetScrollbar(WID_SCRS_SCROLLBAR);
314 this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
315
316 this->RebuildVisibleSettings();
317 }
318
324 void RebuildVisibleSettings()
325 {
326 visible_settings.clear();
327
328 for (const auto &item : *this->script_config->GetConfigList()) {
329 bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
330 if (no_hide || _settings_client.gui.ai_developer_tools) {
331 visible_settings.push_back(&item);
332 }
333 }
334
335 this->vscroll->SetCount(this->visible_settings.size());
336 }
337
338 void SetStringParameters(WidgetID widget) const override
339 {
340 if (widget != WID_SCRS_CAPTION) return;
341
342 SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
343 }
344
345 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
346 {
347 if (widget != WID_SCRS_BACKGROUND) return;
348
349 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
350
351 resize->width = 1;
352 resize->height = this->line_height;
353 size->height = 5 * this->line_height;
354 }
355
356 void DrawWidget(const Rect &r, WidgetID widget) const override
357 {
358 if (widget != WID_SCRS_BACKGROUND) return;
359
360 ScriptConfig *config = this->script_config;
361 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
362 int i = 0;
363 for (; !this->vscroll->IsVisible(i); i++) it++;
364
365 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
366 bool rtl = _current_text_dir == TD_RTL;
367 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
368 Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
369
370 int y = r.top;
371 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
372 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
373 for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
374 const ScriptConfigItem &config_item = **it;
375 int current_value = config->GetSetting((config_item).name);
376 bool editable = this->IsEditableItem(config_item);
377
378 StringID str;
379 TextColour colour;
380 uint idx = 0;
381 if (config_item.description.empty()) {
382 if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
383 str = STR_AI_SETTINGS_JUST_DEVIATION;
384 } else {
385 str = STR_JUST_STRING1;
386 }
387 colour = TC_ORANGE;
388 } else {
389 if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
390 str = STR_AI_SETTINGS_SETTING_DEVIATION;
391 } else {
392 str = STR_AI_SETTINGS_SETTING;
393 }
394 colour = TC_LIGHT_BLUE;
395 SetDParamStr(idx++, config_item.description);
396 }
397
398 if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
399 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
400 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
401 } else {
402 if (config_item.complete_labels) {
403 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
404 } else {
405 DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
406 }
407
408 if (this->slot == OWNER_DEITY || Company::IsValidID(this->slot) || config_item.random_deviation == 0) {
409 auto config_iterator = config_item.labels.find(current_value);
410 if (config_iterator != config_item.labels.end()) {
411 SetDParam(idx++, STR_JUST_RAW_STRING);
412 SetDParamStr(idx++, config_iterator->second);
413 } else {
414 SetDParam(idx++, STR_JUST_INT);
415 SetDParam(idx++, current_value);
416 }
417 } else {
418 int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
419 auto config_iterator = config_item.labels.find(min_deviated);
420 if (config_iterator != config_item.labels.end()) {
421 SetDParam(idx++, STR_JUST_RAW_STRING);
422 SetDParamStr(idx++, config_iterator->second);
423 } else {
424 SetDParam(idx++, STR_JUST_INT);
425 SetDParam(idx++, min_deviated);
426 }
427
428 int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
429 config_iterator = config_item.labels.find(max_deviated);
430 if (config_iterator != config_item.labels.end()) {
431 SetDParam(idx++, STR_JUST_RAW_STRING);
432 SetDParamStr(idx++, config_iterator->second);
433 } else {
434 SetDParam(idx++, STR_JUST_INT);
435 SetDParam(idx++, max_deviated);
436 }
437 }
438 }
439
440 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
441 y += this->line_height;
442 }
443 }
444
445 void OnPaint() override
446 {
447 if (this->closing_dropdown) {
448 this->closing_dropdown = false;
449 this->clicked_dropdown = false;
450 }
451 this->DrawWidgets();
452 }
453
454 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
455 {
456 switch (widget) {
457 case WID_SCRS_BACKGROUND: {
458 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
459 if (it == this->visible_settings.end()) break;
460
461 const ScriptConfigItem &config_item = **it;
462 if (!this->IsEditableItem(config_item)) return;
463
464 int num = it - this->visible_settings.begin();
465 if (this->clicked_row != num) {
466 this->CloseChildWindows(WC_QUERY_STRING);
467 this->CloseChildWindows(WC_DROPDOWN_MENU);
468 this->clicked_row = num;
469 this->clicked_dropdown = false;
470 }
471
472 bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
473
474 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
475 int x = pt.x - r.left;
476 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
477
478 /* One of the arrows is clicked (or green/red rect in case of bool value) */
479 int old_val = this->script_config->GetSetting(config_item.name);
480 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
481 if (this->clicked_dropdown) {
482 /* unclick the dropdown */
483 this->CloseChildWindows(WC_DROPDOWN_MENU);
484 this->clicked_dropdown = false;
485 this->closing_dropdown = false;
486 } else {
487 int rel_y = (pt.y - r.top) % this->line_height;
488
489 Rect wi_rect;
490 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
491 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
492 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
493 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
494
495 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
496 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
497 this->clicked_dropdown = true;
498 this->closing_dropdown = false;
499
500 DropDownList list;
501 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
502 list.push_back(std::make_unique<DropDownListStringItem>(config_item.labels.find(i)->second, i, false));
503 }
504
505 ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
506 }
507 }
508 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
509 int new_val = old_val;
510 if (bool_item) {
511 new_val = !new_val;
512 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
513 /* Increase button clicked */
514 new_val += config_item.step_size;
515 if (new_val > config_item.max_value) new_val = config_item.max_value;
516 this->clicked_increase = true;
517 } else {
518 /* Decrease button clicked */
519 new_val -= config_item.step_size;
520 if (new_val < config_item.min_value) new_val = config_item.min_value;
521 this->clicked_increase = false;
522 }
523
524 if (new_val != old_val) {
525 this->script_config->SetSetting(config_item.name, new_val);
526 this->clicked_button = num;
527 this->unclick_timeout.Reset();
528 }
529 } else if (!bool_item && !config_item.complete_labels) {
530 /* Display a query box so users can enter a custom value. */
531 SetDParam(0, old_val);
532 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE);
533 }
534 this->SetDirty();
535 break;
536 }
537
538 case WID_SCRS_ACCEPT:
539 this->Close();
540 break;
541
542 case WID_SCRS_RESET:
543 this->script_config->ResetEditableSettings(_game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
544 this->SetDirty();
545 break;
546 }
547 }
548
549 void OnQueryTextFinished(char *str) override
550 {
551 if (StrEmpty(str)) return;
552 int32_t value = atoi(str);
553
554 SetValue(value);
555 }
556
557 void OnDropdownSelect(WidgetID widget, int index) override
558 {
559 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
560 assert(this->clicked_dropdown);
561 SetValue(index);
562 }
563
564 void OnDropdownClose(Point, WidgetID widget, int, bool) override
565 {
566 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
567 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
568 * the same dropdown button was clicked again, and then not open the dropdown again.
569 * So, we only remember that it was closed, and process it on the next OnPaint, which is
570 * after OnClick. */
571 assert(this->clicked_dropdown);
572 this->closing_dropdown = true;
573 this->SetDirty();
574 }
575
576 void OnResize() override
577 {
578 this->vscroll->SetCapacityFromWidget(this, WID_SCRS_BACKGROUND);
579 }
580
582 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
583 this->clicked_button = -1;
584 this->SetDirty();
585 }};
586
592 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
593 {
594 this->RebuildVisibleSettings();
595 this->CloseChildWindows(WC_DROPDOWN_MENU);
596 this->CloseChildWindows(WC_QUERY_STRING);
597 }
598
599 private:
600 bool IsEditableItem(const ScriptConfigItem &config_item) const
601 {
602 return _game_mode == GM_MENU
603 || _game_mode == GM_EDITOR
604 || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot))
605 || (config_item.flags & SCRIPTCONFIG_INGAME) != 0
606 || _settings_client.gui.ai_developer_tools;
607 }
608
609 void SetValue(int value)
610 {
611 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
612 if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
613 this->script_config->SetSetting(config_item.name, value);
614 this->SetDirty();
615 }
616 };
617
619 static constexpr NWidgetPart _nested_script_settings_widgets[] = {
620 NWidget(NWID_HORIZONTAL),
621 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
622 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
623 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
624 EndContainer(),
625 NWidget(NWID_HORIZONTAL),
626 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_SCRS_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_SCRS_SCROLLBAR),
627 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRS_SCROLLBAR),
628 EndContainer(),
629 NWidget(NWID_HORIZONTAL),
630 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
631 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
632 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
633 EndContainer(),
634 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
635 EndContainer(),
636 };
637
639 static WindowDesc _script_settings_desc(__FILE__, __LINE__,
640 WDP_CENTER, "settings_script", 500, 208,
641 WC_SCRIPT_SETTINGS, WC_NONE,
642 0,
643 std::begin(_nested_script_settings_widgets), std::end(_nested_script_settings_widgets)
644 );
645
650 void ShowScriptSettingsWindow(CompanyID slot)
651 {
652 CloseWindowByClass(WC_SCRIPT_LIST);
653 CloseWindowByClass(WC_SCRIPT_SETTINGS);
654 new ScriptSettingsWindow(&_script_settings_desc, slot);
655 }
656
657
659 struct ScriptTextfileWindow : public TextfileWindow {
660 CompanyID slot;
661
662 ScriptTextfileWindow(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
663 {
664 this->ConstructWindow();
665 this->OnInvalidateData();
666 }
667
668 void SetStringParameters(WidgetID widget) const override
669 {
670 if (widget == WID_TF_CAPTION) {
671 SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
672 SetDParamStr(1, GetConfig(slot)->GetInfo()->GetName());
673 }
674 }
675
676 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
677 {
678 auto textfile = GetConfig(slot)->GetTextfile(file_type, slot);
679 if (!textfile.has_value()) {
680 this->Close();
681 } else {
682 this->LoadTextfile(textfile.value(), (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
683 }
684 }
685 };
686
692 void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
693 {
694 CloseWindowById(WC_TEXTFILE, file_type);
695 new ScriptTextfileWindow(file_type, slot);
696 }
697
698
707 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
708 {
709 /* Dead scripts are indicated with red background and
710 * paused scripts are indicated with yellow background. */
711 Colours colour = dead ? COLOUR_RED :
712 (paused ? COLOUR_YELLOW : COLOUR_GREY);
713 if (button.colour != colour) {
714 button.colour = colour;
715 return true;
716 }
717 return false;
718 }
719
723 struct ScriptDebugWindow : public Window {
724 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
725
726 struct FilterState {
727 std::string break_string;
728 CompanyID script_debug_company;
729 bool break_check_enabled;
730 bool case_sensitive_break_check;
731 };
732
733 static inline FilterState initial_state = {
734 "",
735 INVALID_COMPANY,
736 true,
737 false,
738 };
739
740 int redraw_timer;
741 int last_vscroll_pos;
742 bool autoscroll;
743 bool show_break_box;
744 QueryString break_editbox;
745 StringFilter break_string_filter;
746 int highlight_row;
747 Scrollbar *vscroll;
748 Scrollbar *hscroll;
749 FilterState filter;
750
751 ScriptLogTypes::LogData &GetLogData() const
752 {
753 if (this->filter.script_debug_company == OWNER_DEITY) return Game::GetInstance()->GetLogData();
754 return Company::Get(this->filter.script_debug_company)->ai_instance->GetLogData();
755 }
756
761 bool IsDead() const
762 {
763 if (this->filter.script_debug_company == OWNER_DEITY) {
764 GameInstance *game = Game::GetInstance();
765 return game == nullptr || game->IsDead();
766 }
767 return !Company::IsValidAiID(this->filter.script_debug_company) || Company::Get(this->filter.script_debug_company)->ai_instance->IsDead();
768 }
769
775 bool IsValidDebugCompany(CompanyID company) const
776 {
777 switch (company) {
778 case INVALID_COMPANY: return false;
779 case OWNER_DEITY: return Game::GetInstance() != nullptr;
780 default: return Company::IsValidAiID(company);
781 }
782 }
783
788 void SelectValidDebugCompany()
789 {
790 /* Check if the currently selected company is still active. */
791 if (this->IsValidDebugCompany(this->filter.script_debug_company)) return;
792
793 this->filter.script_debug_company = INVALID_COMPANY;
794
795 for (const Company *c : Company::Iterate()) {
796 if (c->is_ai) {
797 ChangeToScript(c->index);
798 return;
799 }
800 }
801
802 /* If no AI is available, see if there is a game script. */
803 if (Game::GetInstance() != nullptr) ChangeToScript(OWNER_DEITY);
804 }
805
811 ScriptDebugWindow(WindowDesc *desc, WindowNumber number, Owner show_company) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
812 {
813 this->filter = ScriptDebugWindow::initial_state;
814 this->break_string_filter = {&this->filter.case_sensitive_break_check, false};
815
816 this->CreateNestedTree();
817 this->vscroll = this->GetScrollbar(WID_SCRD_VSCROLLBAR);
818 this->hscroll = this->GetScrollbar(WID_SCRD_HSCROLLBAR);
819 this->FinishInitNested(number);
820
821 this->last_vscroll_pos = 0;
822 this->autoscroll = true;
823 this->highlight_row = -1;
824
825 this->querystrings[WID_SCRD_BREAK_STR_EDIT_BOX] = &this->break_editbox;
826
827 this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar
828
829 /* Restore the break string value from static variable, and enable the filter. */
830 this->break_editbox.text.Assign(this->filter.break_string);
831 this->break_string_filter.SetFilterTerm(this->filter.break_string);
832
833 if (show_company == INVALID_COMPANY) {
834 this->SelectValidDebugCompany();
835 } else {
836 this->ChangeToScript(show_company);
837 }
838 }
839
840 void OnInit() override
841 {
842 this->show_break_box = _settings_client.gui.ai_developer_tools;
843 this->GetWidget<NWidgetStacked>(WID_SCRD_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
844 if (!this->show_break_box) this->filter.break_check_enabled = false;
845 SetWidgetsDisabledState(!this->show_break_box, WID_SCRD_BREAK_STR_ON_OFF_BTN, WID_SCRD_BREAK_STR_EDIT_BOX, WID_SCRD_MATCH_CASE_BTN);
846
847 this->InvalidateData(-1);
848 }
849
850 ~ScriptDebugWindow()
851 {
852 ScriptDebugWindow::initial_state = this->filter;
853 }
854
855 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
856 {
857 if (widget == WID_SCRD_LOG_PANEL) {
858 resize->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
859 size->height = 14 * resize->height + WidgetDimensions::scaled.framerect.Vertical();
860 }
861 }
862
863 void OnPaint() override
864 {
865 this->SelectValidDebugCompany();
866 this->UpdateLogScroll();
867
868 /* Draw standard stuff */
869 this->DrawWidgets();
870 }
871
872 void SetStringParameters(WidgetID widget) const override
873 {
874 if (widget != WID_SCRD_NAME_TEXT) return;
875
876 if (this->filter.script_debug_company == OWNER_DEITY) {
877 const GameInfo *info = Game::GetInfo();
878 assert(info != nullptr);
879 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
880 SetDParamStr(1, info->GetName());
881 SetDParam(2, info->GetVersion());
882 } else if (this->filter.script_debug_company == INVALID_COMPANY || !Company::IsValidAiID(this->filter.script_debug_company)) {
883 SetDParam(0, STR_EMPTY);
884 } else {
885 const AIInfo *info = Company::Get(this->filter.script_debug_company)->ai_info;
886 assert(info != nullptr);
887 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
888 SetDParamStr(1, info->GetName());
889 SetDParam(2, info->GetVersion());
890 }
891 }
892
893 void DrawWidget(const Rect &r, WidgetID widget) const override
894 {
895 switch (widget) {
896 case WID_SCRD_LOG_PANEL:
897 this->DrawWidgetLog(r);
898 break;
899
900 default:
901 if (IsInsideBS(widget, WID_SCRD_COMPANY_BUTTON_START, MAX_COMPANIES)) {
902 this->DrawWidgetCompanyButton(r, widget, WID_SCRD_COMPANY_BUTTON_START);
903 }
904 break;
905 }
906 }
907
914 void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
915 {
916 if (this->IsWidgetDisabled(widget)) return;
917 CompanyID cid = (CompanyID)(widget - start);
918 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
919 DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
920 }
921
926 void DrawWidgetLog(const Rect &r) const
927 {
928 if (this->filter.script_debug_company == INVALID_COMPANY) return;
929
930 ScriptLogTypes::LogData &log = this->GetLogData();
931 if (log.empty()) return;
932
933 Rect fr = r.Shrink(WidgetDimensions::scaled.framerect);
934
935 /* Setup a clipping rectangle... */
936 DrawPixelInfo tmp_dpi;
937 if (!FillDrawPixelInfo(&tmp_dpi, fr)) return;
938 /* ...but keep coordinates relative to the window. */
939 tmp_dpi.left += fr.left;
940 tmp_dpi.top += fr.top;
941
942 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
943
944 fr.left -= this->hscroll->GetPosition();
945
946 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && (size_t)i < log.size(); i++) {
947 const ScriptLogTypes::LogLine &line = log[i];
948
949 TextColour colour;
950 switch (line.type) {
951 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break;
952 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break;
953 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break;
954 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break;
955 case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break;
956 default: colour = TC_BLACK; break;
957 }
958
959 /* Check if the current line should be highlighted */
960 if (i == this->highlight_row) {
961 fr.bottom = fr.top + this->resize.step_height - 1;
962 GfxFillRect(fr, PC_BLACK);
963 if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
964 }
965
966 DrawString(fr, line.text, colour, SA_LEFT | SA_FORCE);
967 fr.top += this->resize.step_height;
968 }
969 }
970
974 void UpdateLogScroll()
975 {
976 this->SetWidgetsDisabledState(this->filter.script_debug_company == INVALID_COMPANY, WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR);
977 if (this->filter.script_debug_company == INVALID_COMPANY) return;
978
979 ScriptLogTypes::LogData &log = this->GetLogData();
980
981 int scroll_count = (int)log.size();
982 if (this->vscroll->GetCount() != scroll_count) {
983 this->vscroll->SetCount(scroll_count);
984
985 /* We need a repaint */
986 this->SetWidgetDirty(WID_SCRD_VSCROLLBAR);
987 }
988
989 if (log.empty()) return;
990
991 /* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */
992 if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
993 this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= (int)log.size();
994 }
995
996 if (this->autoscroll && this->vscroll->SetPosition((int)log.size())) {
997 /* We need a repaint */
998 this->SetWidgetDirty(WID_SCRD_VSCROLLBAR);
999 this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
1000 }
1001
1002 this->last_vscroll_pos = this->vscroll->GetPosition();
1003 }
1004
1008 void UpdateAIButtonsState()
1009 {
1010 /* Update company buttons */
1011 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1012 /* Mark dead/paused AIs by setting the background colour. */
1013 bool valid = Company::IsValidAiID(i);
1014 bool dead = valid && Company::Get(i)->ai_instance->IsDead();
1015 bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
1016
1017 NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_SCRD_COMPANY_BUTTON_START + i);
1018 button->SetDisabled(!valid);
1019 button->SetLowered(this->filter.script_debug_company == i);
1020 SetScriptButtonColour(*button, dead, paused);
1021 }
1022 }
1023
1027 void UpdateGSButtonState()
1028 {
1029 GameInstance *game = Game::GetInstance();
1030 bool valid = game != nullptr;
1031 bool dead = valid && game->IsDead();
1032 bool paused = valid && game->IsPaused();
1033
1034 NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_SCRD_SCRIPT_GAME);
1035 button->SetDisabled(!valid);
1036 button->SetLowered(this->filter.script_debug_company == OWNER_DEITY);
1037 SetScriptButtonColour(*button, dead, paused);
1038 }
1039
1045 void ChangeToScript(CompanyID show_script, bool new_window = false)
1046 {
1047 if (!this->IsValidDebugCompany(show_script)) return;
1048
1049 if (new_window) {
1050 ScriptDebugWindow::initial_state = this->filter;
1051 ShowScriptDebugWindow(show_script, true);
1052 return;
1053 }
1054
1055 this->filter.script_debug_company = show_script;
1056
1057 this->highlight_row = -1; // The highlight of one Script make little sense for another Script.
1058
1059 /* Close AI settings window to prevent confusion */
1060 CloseWindowByClass(WC_SCRIPT_SETTINGS);
1061
1062 this->InvalidateData(-1);
1063
1064 this->autoscroll = true;
1065 this->last_vscroll_pos = this->vscroll->GetPosition();
1066 }
1067
1068 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1069 {
1070 /* Also called for hotkeys, so check for disabledness */
1071 if (this->IsWidgetDisabled(widget)) return;
1072
1073 /* Check which button is clicked */
1074 if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) {
1075 ChangeToScript((CompanyID)(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed);
1076 }
1077
1078 switch (widget) {
1079 case WID_SCRD_SCRIPT_GAME:
1080 ChangeToScript(OWNER_DEITY, _ctrl_pressed);
1081 break;
1082
1083 case WID_SCRD_RELOAD_TOGGLE:
1084 if (this->filter.script_debug_company == OWNER_DEITY) break;
1085 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1086 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, this->filter.script_debug_company, CRR_MANUAL, INVALID_CLIENT_ID);
1087 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, this->filter.script_debug_company, CRR_NONE, INVALID_CLIENT_ID);
1088 break;
1089
1090 case WID_SCRD_SETTINGS:
1091 ShowScriptSettingsWindow(this->filter.script_debug_company);
1092 break;
1093
1094 case WID_SCRD_BREAK_STR_ON_OFF_BTN:
1095 this->filter.break_check_enabled = !this->filter.break_check_enabled;
1096 this->InvalidateData(-1);
1097 break;
1098
1099 case WID_SCRD_MATCH_CASE_BTN:
1100 this->filter.case_sensitive_break_check = !this->filter.case_sensitive_break_check;
1101 this->InvalidateData(-1);
1102 break;
1103
1104 case WID_SCRD_CONTINUE_BTN:
1105 /* Unpause current AI / game script and mark the corresponding script button dirty. */
1106 if (!this->IsDead()) {
1107 if (this->filter.script_debug_company == OWNER_DEITY) {
1108 Game::Unpause();
1109 } else {
1110 AI::Unpause(this->filter.script_debug_company);
1111 }
1112 }
1113
1114 /* If the last AI/Game Script is unpaused, unpause the game too. */
1115 if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
1116 bool all_unpaused = !Game::IsPaused();
1117 if (all_unpaused) {
1118 for (const Company *c : Company::Iterate()) {
1119 if (c->is_ai && AI::IsPaused(c->index)) {
1120 all_unpaused = false;
1121 break;
1122 }
1123 }
1124 if (all_unpaused) {
1125 /* All scripts have been unpaused => unpause the game. */
1126 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, false);
1127 }
1128 }
1129 }
1130
1131 this->highlight_row = -1;
1132 this->InvalidateData(-1);
1133 break;
1134 }
1135 }
1136
1137 void OnEditboxChanged(WidgetID wid) override
1138 {
1139 if (wid != WID_SCRD_BREAK_STR_EDIT_BOX) return;
1140
1141 /* Save the current string to static member so it can be restored next time the window is opened. */
1142 this->filter.break_string = this->break_editbox.text.buf;
1143 this->break_string_filter.SetFilterTerm(this->filter.break_string);
1144 }
1145
1152 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1153 {
1154 if (this->show_break_box != _settings_client.gui.ai_developer_tools) this->ReInit();
1155
1156 /* If the log message is related to the active company tab, check the break string.
1157 * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1158 if (!gui_scope && data == this->filter.script_debug_company &&
1159 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1160 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1161 /* Get the log instance of the active company */
1162 ScriptLogTypes::LogData &log = this->GetLogData();
1163
1164 if (!log.empty()) {
1165 this->break_string_filter.ResetState();
1166 this->break_string_filter.AddLine(log.back().text);
1167 if (this->break_string_filter.GetState()) {
1168 /* Pause execution of script. */
1169 if (!this->IsDead()) {
1170 if (this->filter.script_debug_company == OWNER_DEITY) {
1171 Game::Pause();
1172 } else {
1173 AI::Pause(this->filter.script_debug_company);
1174 }
1175 }
1176
1177 /* Pause the game. */
1178 if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
1179 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
1180 }
1181
1182 /* Highlight row that matched */
1183 this->highlight_row = (int)(log.size() - 1);
1184 }
1185 }
1186 }
1187
1188 if (!gui_scope) return;
1189
1190 this->SelectValidDebugCompany();
1191
1192 uint max_width = 0;
1193 if (this->filter.script_debug_company != INVALID_COMPANY) {
1194 for (auto &line : this->GetLogData()) {
1195 if (line.width == 0 || data == -1) line.width = GetStringBoundingBox(line.text).width;
1196 max_width = std::max(max_width, line.width);
1197 }
1198 }
1199
1200 this->vscroll->SetCount(this->filter.script_debug_company != INVALID_COMPANY ? this->GetLogData().size() : 0);
1201 this->hscroll->SetCount(max_width + WidgetDimensions::scaled.frametext.Horizontal());
1202
1203 this->UpdateAIButtonsState();
1204 this->UpdateGSButtonState();
1205
1206 this->SetWidgetLoweredState(WID_SCRD_BREAK_STR_ON_OFF_BTN, this->filter.break_check_enabled);
1207 this->SetWidgetLoweredState(WID_SCRD_MATCH_CASE_BTN, this->filter.case_sensitive_break_check);
1208
1209 this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == INVALID_COMPANY);
1210 extern CompanyID _local_company;
1211 this->SetWidgetDisabledState(WID_SCRD_RELOAD_TOGGLE,
1212 this->filter.script_debug_company == INVALID_COMPANY ||
1213 this->filter.script_debug_company == OWNER_DEITY ||
1214 this->filter.script_debug_company == _local_company);
1215 this->SetWidgetDisabledState(WID_SCRD_CONTINUE_BTN, this->filter.script_debug_company == INVALID_COMPANY ||
1216 (this->filter.script_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(this->filter.script_debug_company)));
1217 }
1218
1219 void OnResize() override
1220 {
1221 this->vscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Vertical());
1222 this->hscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL);
1223 }
1224
1230 static EventState ScriptDebugGlobalHotkeys(int hotkey)
1231 {
1232 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1233 Window *w = ShowScriptDebugWindow(INVALID_COMPANY);
1234 if (w == nullptr) return ES_NOT_HANDLED;
1235 return w->OnHotkey(hotkey);
1236 }
1237
1238 static inline HotkeyList hotkeys{"aidebug", {
1239 Hotkey('1', "company_1", WID_SCRD_COMPANY_BUTTON_START),
1240 Hotkey('2', "company_2", WID_SCRD_COMPANY_BUTTON_START + 1),
1241 Hotkey('3', "company_3", WID_SCRD_COMPANY_BUTTON_START + 2),
1242 Hotkey('4', "company_4", WID_SCRD_COMPANY_BUTTON_START + 3),
1243 Hotkey('5', "company_5", WID_SCRD_COMPANY_BUTTON_START + 4),
1244 Hotkey('6', "company_6", WID_SCRD_COMPANY_BUTTON_START + 5),
1245 Hotkey('7', "company_7", WID_SCRD_COMPANY_BUTTON_START + 6),
1246 Hotkey('8', "company_8", WID_SCRD_COMPANY_BUTTON_START + 7),
1247 Hotkey('9', "company_9", WID_SCRD_COMPANY_BUTTON_START + 8),
1248 Hotkey(0, "company_10", WID_SCRD_COMPANY_BUTTON_START + 9),
1249 Hotkey(0, "company_11", WID_SCRD_COMPANY_BUTTON_START + 10),
1250 Hotkey(0, "company_12", WID_SCRD_COMPANY_BUTTON_START + 11),
1251 Hotkey(0, "company_13", WID_SCRD_COMPANY_BUTTON_START + 12),
1252 Hotkey(0, "company_14", WID_SCRD_COMPANY_BUTTON_START + 13),
1253 Hotkey(0, "company_15", WID_SCRD_COMPANY_BUTTON_START + 14),
1254 Hotkey('S', "settings", WID_SCRD_SETTINGS),
1255 Hotkey('0', "game_script", WID_SCRD_SCRIPT_GAME),
1256 Hotkey(0, "reload", WID_SCRD_RELOAD_TOGGLE),
1257 Hotkey('B', "break_toggle", WID_SCRD_BREAK_STR_ON_OFF_BTN),
1258 Hotkey('F', "break_string", WID_SCRD_BREAK_STR_EDIT_BOX),
1259 Hotkey('C', "match_case", WID_SCRD_MATCH_CASE_BTN),
1260 Hotkey(WKC_RETURN, "continue", WID_SCRD_CONTINUE_BTN),
1261 }, ScriptDebugGlobalHotkeys};
1262 };
1263
1265 std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsScriptDebug()
1266 {
1267 return MakeCompanyButtonRows(WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END, COLOUR_GREY, 5, STR_AI_DEBUG_SELECT_AI_TOOLTIP, false);
1268 }
1269
1271 static constexpr NWidgetPart _nested_script_debug_widgets[] = {
1272 NWidget(NWID_HORIZONTAL),
1273 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1274 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1275 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1276 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1277 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1278 EndContainer(),
1279 NWidget(NWID_HORIZONTAL),
1280 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_VIEW),
1281 NWidgetFunction(MakeCompanyButtonRowsScriptDebug), SetPadding(0, 2, 1, 2),
1282 EndContainer(),
1283 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_SCRIPT_GAME), SetMinimalSize(100, 20), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
1284 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_NAME_TEXT), SetResize(1, 0), SetDataTip(STR_JUST_STRING2, STR_AI_DEBUG_NAME_TOOLTIP),
1285 NWidget(NWID_VERTICAL),
1286 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_SETTINGS), SetMinimalSize(100, 20), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1287 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1288 EndContainer(),
1289 EndContainer(),
1290 NWidget(NWID_HORIZONTAL),
1291 NWidget(NWID_VERTICAL),
1292 /* Log panel */
1293 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_LOG_PANEL), SetMinimalSize(287, 180), SetResize(1, 1), SetScrollbar(WID_SCRD_VSCROLLBAR),
1294 EndContainer(),
1295 /* Break string widgets */
1296 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCRD_BREAK_STRING_WIDGETS),
1297 NWidget(NWID_HORIZONTAL),
1298 NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_SCRD_BREAK_STR_ON_OFF_BTN), SetFill(0, 1), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
1299 NWidget(WWT_PANEL, COLOUR_GREY),
1300 NWidget(NWID_HORIZONTAL),
1301 NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
1302 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SCRD_BREAK_STR_EDIT_BOX), SetFill(1, 1), SetResize(1, 0), SetPadding(2, 2, 2, 2), SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1303 EndContainer(),
1304 EndContainer(),
1305 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
1306 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
1307 EndContainer(),
1308 EndContainer(),
1309 NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_SCRD_HSCROLLBAR),
1310 EndContainer(),
1311 NWidget(NWID_VERTICAL),
1312 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCRD_VSCROLLBAR),
1313 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1314 EndContainer(),
1315 EndContainer(),
1316 };
1317
1319 static WindowDesc _script_debug_desc(__FILE__, __LINE__,
1320 WDP_AUTO, "script_debug", 600, 450,
1321 WC_SCRIPT_DEBUG, WC_NONE,
1322 0,
1323 std::begin(_nested_script_debug_widgets), std::end(_nested_script_debug_widgets),
1324 &ScriptDebugWindow::hotkeys
1325 );
1326
1332 Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window)
1333 {
1334 if (!_networking || _network_server) {
1335 int i = 0;
1336 if (new_window) {
1337 /* find next free window number for script debug */
1338 while (FindWindowById(WC_SCRIPT_DEBUG, i) != nullptr) i++;
1339 } else {
1340 /* Find existing window showing show_company. */
1341 for (Window *w : Window::Iterate()) {
1342 if (w->window_class == WC_SCRIPT_DEBUG && static_cast<ScriptDebugWindow *>(w)->filter.script_debug_company == show_company) {
1343 return BringWindowToFrontById(w->window_class, w->window_number);
1344 }
1345 }
1346
1347 /* Maybe there's a window showing a different company which can be switched. */
1348 ScriptDebugWindow *w = static_cast<ScriptDebugWindow *>(FindWindowByClass(WC_SCRIPT_DEBUG));
1349 if (w != nullptr) {
1350 BringWindowToFrontById(w->window_class, w->window_number);
1351 w->ChangeToScript(show_company);
1352 return w;
1353 }
1354 }
1355 return new ScriptDebugWindow(&_script_debug_desc, i, show_company);
1356 } else {
1357 ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
1358 }
1359
1360 return nullptr;
1361 }
1362
1366 void InitializeScriptGui()
1367 {
1368 ScriptDebugWindow::initial_state.script_debug_company = INVALID_COMPANY;
1369 }
1370
1372 void ShowScriptDebugWindowIfScriptError()
1373 {
1374 /* Network clients can't debug AIs. */
1375 if (_networking && !_network_server) return;
1376
1377 for (const Company *c : Company::Iterate()) {
1378 if (c->is_ai && c->ai_instance->IsDead()) {
1379 ShowScriptDebugWindow(c->index);
1380 break;
1381 }
1382 }
1383
1384 GameInstance *g = Game::GetGameInstance();
1385 if (g != nullptr && g->IsDead()) {
1386 ShowScriptDebugWindow(OWNER_DEITY);
1387 }
1388 }
ShowScriptDebugWindow
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
Definition: script_gui.cpp:1332
ScriptDebugWindow::FilterState::break_string
std::string break_string
The string to match to the AI output.
Definition: script_gui.cpp:727
WID_SCRD_SCRIPT_GAME
@ WID_SCRD_SCRIPT_GAME
Game Script button.
Definition: script_widget.h:41
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
ScriptDebugWindow::ScriptDebugGlobalHotkeys
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
Definition: script_gui.cpp:1230
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
WC_SCRIPT_DEBUG
@ WC_SCRIPT_DEBUG
Script debug window; Window numbers:
Definition: window_type.h:669
Game::IsPaused
static bool IsPaused()
Checks if the Game Script is paused.
Definition: game_core.cpp:142
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:55
ScriptInfoList
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Definition: script_scanner.hpp:16
ScriptDebugWindow::autoscroll
bool autoscroll
Whether automatically scrolling should be enabled or not.
Definition: script_gui.cpp:742
Game::GetGameInstance
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
Definition: game.hpp:71
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
INT32_DIGITS_WITH_SIGN_AND_TERMINATION
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
Definition: script_config.hpp:18
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
ScriptListWindow::info_list
const ScriptInfoList * info_list
The list of Scripts.
Definition: script_gui.cpp:54
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:39
ScriptDebugWindow::SelectValidDebugCompany
void SelectValidDebugCompany()
Ensure that script_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
Definition: script_gui.cpp:788
ShowScriptListWindow
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Definition: script_gui.cpp:276
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:85
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
ScriptConfigItem::name
std::string name
The name of the configuration setting.
Definition: script_config.hpp:33
ScriptListWindow
Window that let you choose an available Script.
Definition: script_gui.cpp:53
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
ScriptSettingsWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: script_gui.cpp:294
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:405
ScriptDebugWindow::FilterState::break_check_enabled
bool break_check_enabled
Stop an AI when it prints a matching string.
Definition: script_gui.cpp:729
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
Game::GetInfo
static class GameInfo * GetInfo()
Get the current GameInfo.
Definition: game.hpp:76
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:210
WID_SCRD_COMPANY_BUTTON_END
@ WID_SCRD_COMPANY_BUTTON_END
Last possible button in the VIEW.
Definition: script_widget.h:46
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
ScriptListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: script_gui.cpp:58
_nested_script_settings_widgets
static constexpr NWidgetPart _nested_script_settings_widgets[]
Widgets for the Script settings window.
Definition: script_gui.cpp:619
valid
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
Definition: newgrf_station.cpp:246
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
WID_SCRD_SETTINGS
@ WID_SCRD_SETTINGS
Settings button.
Definition: script_widget.h:40
WID_SCRD_RELOAD_TOGGLE
@ WID_SCRD_RELOAD_TOGGLE
Reload button.
Definition: script_widget.h:42
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
ScriptSettingsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: script_gui.cpp:445
ScriptDebugWindow::UpdateGSButtonState
void UpdateGSButtonState()
Update state of game script button.
Definition: script_gui.cpp:1027
ScriptSettingsWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: script_gui.cpp:592
_nested_script_debug_widgets
static constexpr NWidgetPart _nested_script_debug_widgets[]
Widgets for the Script debug window.
Definition: script_gui.cpp:1271
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
ScriptDebugWindow::last_vscroll_pos
int last_vscroll_pos
Last position of the scrolling.
Definition: script_gui.cpp:741
Scrollbar::SetStepSize
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:748
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1174
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
ScriptDebugWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: script_gui.cpp:747
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2334
ScriptListWindow::slot
CompanyID slot
The company we're selecting a new Script for.
Definition: script_gui.cpp:56
ScriptInstance::GetLogData
ScriptLogTypes::LogData & GetLogData()
Get the log pointer of this script.
Definition: script_instance.cpp:319
WID_SCRD_BREAK_STR_ON_OFF_BTN
@ WID_SCRD_BREAK_STR_ON_OFF_BTN
Enable breaking on string.
Definition: script_widget.h:48
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
ScriptSettingsWindow::OnDropdownClose
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
Definition: script_gui.cpp:564
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
Game::Unpause
static void Unpause()
Resume execution of the Game Script.
Definition: game_core.cpp:137
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1279
_nested_script_list_widgets
static constexpr NWidgetPart _nested_script_list_widgets[]
Widgets for the AI list window.
Definition: script_gui.cpp:242
ScriptDebugWindow::ScriptDebugWindow
ScriptDebugWindow(WindowDesc *desc, WindowNumber number, Owner show_company)
Constructor for the window.
Definition: script_gui.cpp:811
InitializeScriptGui
void InitializeScriptGui()
Reset the Script windows to their initial state.
Definition: script_gui.cpp:1366
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
ScriptDebugWindow::redraw_timer
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
Definition: script_gui.cpp:740
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:22
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:566
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:109
ScriptDebugWindow::DrawWidgetCompanyButton
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
Draw a company button icon.
Definition: script_gui.cpp:914
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
ScriptDebugWindow::highlight_row
int highlight_row
The output row that matches the given string, or -1.
Definition: script_gui.cpp:746
SCRIPTCONFIG_BOOLEAN
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:24
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:35
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:702
ScriptDebugWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: script_gui.cpp:1219
ScriptInfo::GetAuthor
const std::string & GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:41
WID_SCRD_COMPANY_BUTTON_START
@ WID_SCRD_COMPANY_BUTTON_START
Buttons in the VIEW.
Definition: script_widget.h:45
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:63
ScriptDebugWindow::show_break_box
bool show_break_box
Whether the break/debug box is visible.
Definition: script_gui.cpp:743
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
TimeoutTimer::Reset
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition: timer.h:140
ScriptListWindow::ScriptListWindow
ScriptListWindow(WindowDesc *desc, CompanyID slot, bool show_all)
Constructor for the window.
Definition: script_gui.cpp:67
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:42
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
ScriptDebugWindow::IsDead
bool IsDead() const
Check whether the currently selected AI/GS is dead.
Definition: script_gui.cpp:761
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:134
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1188
MakeCompanyButtonRows
std::unique_ptr< NWidgetBase > MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3196
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
ScriptDebugWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: script_gui.cpp:840
ScriptListWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: script_gui.cpp:57
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI/GS developer tools
Definition: settings_type.h:217
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:36
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2940
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
ScriptSettingsWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: script_gui.cpp:291
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition: script_info.hpp:76
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition: fileio_type.h:119
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition: company_type.h:69
script_config.hpp
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:56
Game::Pause
static void Pause()
Suspends the Game Script and then pause the execution of the script.
Definition: game_core.cpp:132
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:19
ScriptInstance::IsDead
bool IsDead() const
Return the "this script died" value.
Definition: script_instance.hpp:153
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition: ai_core.cpp:121
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
WID_SCRL_SCROLLBAR
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
Definition: script_widget.h:19
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:765
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:25
_script_settings_desc
static WindowDesc _script_settings_desc(__FILE__, __LINE__, WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, 0, std::begin(_nested_script_settings_widgets), std::end(_nested_script_settings_widgets))
Window definition for the Script settings window.
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:26
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
MakeCompanyButtonRowsScriptDebug
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
Definition: script_gui.cpp:1265
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
ScriptListWindow::show_all
bool show_all
Whether to show all available versions.
Definition: script_gui.cpp:59
WID_SCRS_ACCEPT
@ WID_SCRS_ACCEPT
Accept button.
Definition: script_widget.h:30
ScriptDebugWindow::IsValidDebugCompany
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
Definition: script_gui.cpp:775
ScriptInfo::GetName
const std::string & GetName() const
Get the Name of the script.
Definition: script_info.hpp:46
ScriptSettingsWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition: script_gui.cpp:293
ScriptDebugWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: script_gui.cpp:863
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1086
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition: ai_core.cpp:303
Company::IsValidAiID
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:138
GAME_DIR
@ GAME_DIR
Subdirectory for all game scripts.
Definition: fileio_type.h:121
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
ScriptDebugWindow::hscroll
Scrollbar * hscroll
Cache of the horizontal scrollbar.
Definition: script_gui.cpp:748
ShowScriptSettingsWindow
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
Definition: script_gui.cpp:650
WID_SCRL_INFO_BG
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
Definition: script_widget.h:20
ScriptSettingsWindow::visible_settings
VisibleSettingsList visible_settings
List of visible AI settings.
Definition: script_gui.cpp:297
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:410
ScriptTextfileWindow
Window for displaying the textfile of a AI.
Definition: script_gui.cpp:659
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:845
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2909
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3140
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:142
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:906
ScriptInfo::GetDescription
const std::string & GetDescription() const
Get the description of the script.
Definition: script_info.hpp:56
_script_list_desc
static WindowDesc _script_list_desc(__FILE__, __LINE__, WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, 0, std::begin(_nested_script_list_widgets), std::end(_nested_script_list_widgets))
Window definition for the ai list window.
ScriptConfig::Change
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
Definition: script_config.cpp:21
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1571
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:158
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2260
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
GameInstance
Runtime information about a game script like a pointer to the squirrel vm and the current state.
Definition: game_instance.hpp:16
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
WID_SCRS_CAPTION
@ WID_SCRS_CAPTION
Caption of the window.
Definition: script_widget.h:27
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
ScriptSettingsWindow::slot
CompanyID slot
The currently show company's setting.
Definition: script_gui.cpp:287
WID_SCRS_SETTING_DROPDOWN
@ WID_SCRS_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
Definition: script_widget.h:33
ScriptDebugWindow::MAX_BREAK_STR_STRING_LENGTH
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
Definition: script_gui.cpp:724
WID_SCRD_BREAK_STRING_WIDGETS
@ WID_SCRD_BREAK_STRING_WIDGETS
The panel to handle the breaking on string.
Definition: script_widget.h:47
WID_SCRL_ACCEPT
@ WID_SCRL_ACCEPT
Accept button.
Definition: script_widget.h:21
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:775
ScriptDebugWindow::break_string_filter
StringFilter break_string_filter
Log filter for break.
Definition: script_gui.cpp:745
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
ShowScriptDebugWindowIfScriptError
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: script_gui.cpp:1372
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
TimeoutTimer< TimerWindow >
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
ScriptListWindow::ChangeScript
void ChangeScript()
Changes the Script of the current slot.
Definition: script_gui.cpp:172
ScriptDebugWindow
Window with everything an AI prints via ScriptLog.
Definition: script_gui.cpp:723
ScriptDebugWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: script_gui.cpp:1152
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:61
WID_SCRL_CANCEL
@ WID_SCRL_CANCEL
Cancel button.
Definition: script_widget.h:22
WID_SCRD_NAME_TEXT
@ WID_SCRD_NAME_TEXT
Name of the current selected.
Definition: script_widget.h:39
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:730
WID_SCRD_VSCROLLBAR
@ WID_SCRD_VSCROLLBAR
Vertical scrollbar of the log panel.
Definition: script_widget.h:44
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
ScriptDebugWindow::UpdateAIButtonsState
void UpdateAIButtonsState()
Update state of all Company (AI) buttons.
Definition: script_gui.cpp:1008
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition: company_type.h:63
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3217
ScriptSettingsWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: script_gui.cpp:295
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
ScriptConfig
Script settings.
Definition: script_config.hpp:50
ScriptSettingsWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition: script_gui.cpp:324
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
ScriptListWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: script_gui.cpp:225
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:64
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
ScriptSettingsWindow::VisibleSettingsList
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition: script_gui.cpp:296
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
script_scanner.hpp
ScriptDebugWindow::FilterState::script_debug_company
CompanyID script_debug_company
The AI that is (was last) being debugged.
Definition: script_gui.cpp:728
EventState
EventState
State of handling an event.
Definition: window_type.h:738
GameInfo
All static information from an Game like name, version, etc.
Definition: game_info.hpp:16
WN_GAME_OPTIONS_GS
@ WN_GAME_OPTIONS_GS
GS settings.
Definition: window_type.h:23
ScriptConfig::GetSetting
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
Definition: script_config.cpp:84
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1114
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:295
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:377
ScriptTextfileWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: script_gui.cpp:676
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
WID_SCRD_CONTINUE_BTN
@ WID_SCRD_CONTINUE_BTN
Continue button.
Definition: script_widget.h:51
ScriptTextfileWindow::slot
CompanyID slot
View the textfile of this CompanyID slot.
Definition: script_gui.cpp:660
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:50
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
ScriptListWindow::selected
int selected
The currently selected Script.
Definition: script_gui.cpp:55
ScriptDebugWindow::FilterState
Definition: script_gui.cpp:726
ScriptConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:193
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition: string_type.h:28
WN_GAME_OPTIONS_AI
@ WN_GAME_OPTIONS_AI
AI settings.
Definition: window_type.h:22
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
ScriptDebugWindow::FilterState::case_sensitive_break_check
bool case_sensitive_break_check
Is the matching done case-sensitive.
Definition: script_gui.cpp:730
CommandHelper
Definition: command_func.h:93
WID_SCRS_RESET
@ WID_SCRS_RESET
Reset button.
Definition: script_widget.h:31
WID_SCRL_CAPTION
@ WID_SCRL_CAPTION
Caption of the window.
Definition: script_widget.h:17
WID_SCRD_MATCH_CASE_BTN
@ WID_SCRD_MATCH_CASE_BTN
Checkbox to use match caching or not.
Definition: script_widget.h:50
ScriptDebugWindow::UpdateLogScroll
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
Definition: script_gui.cpp:974
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
_script_debug_desc
static WindowDesc _script_debug_desc(__FILE__, __LINE__, WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, 0, std::begin(_nested_script_debug_widgets), std::end(_nested_script_debug_widgets), &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
ScriptSettingsWindow
Window for settings the parameters of an AI.
Definition: script_gui.cpp:286
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
WID_SCRS_BACKGROUND
@ WID_SCRS_BACKGROUND
Panel to draw the settings on.
Definition: script_widget.h:28
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
ScriptConfigItem::description
std::string description
The description of the configuration setting.
Definition: script_config.hpp:34
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:40
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition: ai_core.cpp:308
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
ScriptInstance::IsPaused
bool IsPaused()
Checks if the script is paused.
Definition: script_instance.cpp:560
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:61
ScriptSettingsWindow::ScriptSettingsWindow
ScriptSettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
Definition: script_gui.cpp:304
ScriptSettingsWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition: script_gui.cpp:290
Window
Data structure for an opened window.
Definition: window_gui.h:267
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
ScriptSettingsWindow::clicked_button
int clicked_button
The button we clicked.
Definition: script_gui.cpp:289
WID_SCRD_HSCROLLBAR
@ WID_SCRD_HSCROLLBAR
Horizontal scrollbar of the log panel.
Definition: script_widget.h:52
WID_SCRD_VIEW
@ WID_SCRD_VIEW
The row of company buttons.
Definition: script_widget.h:38
ScriptSettingsWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: script_gui.cpp:292
ScriptDebugWindow::break_editbox
QueryString break_editbox
Break editbox.
Definition: script_gui.cpp:744
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
ScriptConfigItem::labels
LabelMapping labels
Text labels for the integer values.
Definition: script_config.hpp:41
ScriptDebugWindow::ChangeToScript
void ChangeToScript(CompanyID show_script, bool new_window=false)
Change all settings to select another Script.
Definition: script_gui.cpp:1045
WID_SCRL_LIST
@ WID_SCRL_LIST
The matrix with all available Scripts.
Definition: script_widget.h:18
Game::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
Definition: game_core.cpp:238
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
Definition: script_gui.cpp:692
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2961
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1109
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition: window_type.h:175
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:70
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
ScriptSettingsWindow::script_config
ScriptConfig * script_config
The configuration we're modifying.
Definition: script_gui.cpp:288
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition: window_type.h:284
Game::GetInstance
static class GameInstance * GetInstance()
Get the current active instance.
Definition: game.hpp:102
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Company
Definition: company_base.h:116
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:32
WID_SCRD_BREAK_STR_EDIT_BOX
@ WID_SCRD_BREAK_STR_EDIT_BOX
Edit box for the string to break on.
Definition: script_widget.h:49
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
ScriptConfigItem::random_deviation
int random_deviation
The maximum random deviation from the default value.
Definition: script_config.hpp:38
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:187
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
ScriptConfig::SetSetting
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:91
ScriptSettingsWindow::unclick_timeout
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition: script_gui.cpp:582
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
ScriptSettingsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: script_gui.cpp:576
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
ScriptDebugWindow::DrawWidgetLog
void DrawWidgetLog(const Rect &r) const
Draw the AI/GS log.
Definition: script_gui.cpp:926
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition: company_type.h:57
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
ScriptListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: script_gui.cpp:215
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition: widget_type.h:429
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
WID_SCRD_LOG_PANEL
@ WID_SCRD_LOG_PANEL
Panel where the log is in.
Definition: script_widget.h:43
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:790
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:332
Game::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for GameScanner::GetInfoList.
Definition: game_core.cpp:233
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
WID_SCRS_SCROLLBAR
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: script_widget.h:29
SetScriptButtonColour
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
Definition: script_gui.cpp:707
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66