OpenTTD Source: src/ai/ai_gui.cpp Source File

OpenTTD Source 13.2.1

ai_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 "../strings_func.h"
19 #include "../window_func.h"
20 #include "../gfx_func.h"
21 #include "../command_func.h"
22 #include "../network/network.h"
23 #include "../settings_func.h"
24 #include "../network/network_content.h"
25 #include "../textfile_gui.h"
26 #include "../widgets/dropdown_type.h"
27 #include "../widgets/dropdown_func.h"
28 #include "../hotkeys.h"
29 #include "../core/geometry_func.hpp"
30 #include "../guitimer_func.h"
31 #include "../company_cmd.h"
32 #include "../misc_cmd.h"
33
34 #include "ai.hpp"
35 #include "ai_gui.hpp"
36 #include "../script/api/script_log.hpp"
37 #include "ai_config.hpp"
38 #include "ai_info.hpp"
39 #include "ai_instance.hpp"
40 #include "../game/game.hpp"
41 #include "../game/game_config.hpp"
42 #include "../game/game_info.hpp"
43 #include "../game/game_instance.hpp"
44
45 #include "table/strings.h"
46
47 #include <vector>
48
49 #include "../safeguards.h"
50
51 static ScriptConfig *GetConfig(CompanyID slot)
52 {
53 if (slot == OWNER_DEITY) return GameConfig::GetConfig();
54 return AIConfig::GetConfig(slot);
55 }
56
60 struct AIListWindow : public Window {
61 const ScriptInfoList *info_list;
62 int selected;
63 CompanyID slot;
64 int line_height;
65 Scrollbar *vscroll;
66
72 AIListWindow(WindowDesc *desc, CompanyID slot) : Window(desc),
73 slot(slot)
74 {
75 if (slot == OWNER_DEITY) {
76 this->info_list = Game::GetUniqueInfoList();
77 } else {
78 this->info_list = AI::GetUniqueInfoList();
79 }
80
81 this->CreateNestedTree();
82 this->vscroll = this->GetScrollbar(WID_AIL_SCROLLBAR);
83 this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
84
85 this->vscroll->SetCount((int)this->info_list->size() + 1);
86
87 /* Try if we can find the currently selected AI */
88 this->selected = -1;
89 if (GetConfig(slot)->HasScript()) {
90 ScriptInfo *info = GetConfig(slot)->GetInfo();
91 int i = 0;
92 for (const auto &item : *this->info_list) {
93 if (item.second == info) {
94 this->selected = i;
95 break;
96 }
97
98 i++;
99 }
100 }
101 }
102
103 void SetStringParameters(int widget) const override
104 {
105 switch (widget) {
106 case WID_AIL_CAPTION:
107 SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
108 break;
109 }
110 }
111
112 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
113 {
114 if (widget == WID_AIL_LIST) {
115 this->line_height = FONT_HEIGHT_NORMAL + padding.height;
116
117 resize->width = 1;
118 resize->height = this->line_height;
119 size->height = 5 * this->line_height;
120 }
121 }
122
123 void DrawWidget(const Rect &r, int widget) const override
124 {
125 switch (widget) {
126 case WID_AIL_LIST: {
127 /* Draw a list of all available AIs. */
128 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
129 /* First AI in the list is hardcoded to random */
130 if (this->vscroll->IsVisible(0)) {
131 DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
132 tr.top += this->line_height;
133 }
134 int i = 0;
135 for (const auto &item : *this->info_list) {
136 i++;
137 if (this->vscroll->IsVisible(i)) {
138 DrawString(tr, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
139 tr.top += this->line_height;
140 }
141 }
142 break;
143 }
144 case WID_AIL_INFO_BG: {
145 ScriptInfo *selected_info = nullptr;
146 int i = 0;
147 for (const auto &item : *this->info_list) {
148 i++;
149 if (this->selected == i - 1) selected_info = static_cast<ScriptInfo *>(item.second);
150 }
151 /* Some info about the currently selected AI. */
152 if (selected_info != nullptr) {
153 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
154 SetDParamStr(0, selected_info->GetAuthor());
155 DrawString(tr, STR_AI_LIST_AUTHOR);
156 tr.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
157 SetDParam(0, selected_info->GetVersion());
158 DrawString(tr, STR_AI_LIST_VERSION);
159 tr.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
160 if (selected_info->GetURL() != nullptr) {
161 SetDParamStr(0, selected_info->GetURL());
162 DrawString(tr, STR_AI_LIST_URL);
163 tr.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
164 }
165 SetDParamStr(0, selected_info->GetDescription());
166 DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_WHITE);
167 }
168 break;
169 }
170 }
171 }
172
176 void ChangeAI()
177 {
178 if (this->selected == -1) {
179 GetConfig(slot)->Change(nullptr);
180 } else {
181 ScriptInfoList::const_iterator it = this->info_list->begin();
182 for (int i = 0; i < this->selected; i++) it++;
183 GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion());
184 }
185 InvalidateWindowData(WC_GAME_OPTIONS, slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI);
186 InvalidateWindowClassesData(WC_AI_SETTINGS);
187 CloseWindowByClass(WC_QUERY_STRING);
188 InvalidateWindowClassesData(WC_TEXTFILE);
189 }
190
191 void OnClick(Point pt, int widget, int click_count) override
192 {
193 switch (widget) {
194 case WID_AIL_LIST: { // Select one of the AIs
195 int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST) - 1;
196 if (sel < (int)this->info_list->size()) {
197 this->selected = sel;
198 this->SetDirty();
199 if (click_count > 1) {
200 this->ChangeAI();
201 this->Close();
202 }
203 }
204 break;
205 }
206
207 case WID_AIL_ACCEPT: {
208 this->ChangeAI();
209 this->Close();
210 break;
211 }
212
213 case WID_AIL_CANCEL:
214 this->Close();
215 break;
216 }
217 }
218
219 void OnResize() override
220 {
221 this->vscroll->SetCapacityFromWidget(this, WID_AIL_LIST);
222 }
223
229 void OnInvalidateData(int data = 0, bool gui_scope = true) override
230 {
231 if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
232 this->Close();
233 return;
234 }
235
236 if (!gui_scope) return;
237
238 this->vscroll->SetCount((int)this->info_list->size() + 1);
239
240 /* selected goes from -1 .. length of ai list - 1. */
241 this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
242 }
243 };
244
246 static const NWidgetPart _nested_ai_list_widgets[] = {
247 NWidget(NWID_HORIZONTAL),
248 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
249 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
250 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
251 EndContainer(),
252 NWidget(NWID_HORIZONTAL),
253 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIL_LIST), SetMinimalSize(188, 112), SetFill(1, 1), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP), SetScrollbar(WID_AIL_SCROLLBAR),
254 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIL_SCROLLBAR),
255 EndContainer(),
256 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIL_INFO_BG), SetMinimalTextLines(8, WidgetDimensions::unscaled.framerect.Vertical() + WidgetDimensions::unscaled.vsep_normal * 3), SetResize(1, 0),
257 EndContainer(),
258 NWidget(NWID_HORIZONTAL),
259 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
260 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
261 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
262 EndContainer(),
263 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
264 EndContainer(),
265 };
266
268 static WindowDesc _ai_list_desc(
269 WDP_CENTER, "settings_script_list", 200, 234,
270 WC_AI_LIST, WC_NONE,
271 0,
272 _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets)
273 );
274
279 void ShowAIListWindow(CompanyID slot)
280 {
281 CloseWindowByClass(WC_AI_LIST);
282 new AIListWindow(&_ai_list_desc, slot);
283 }
284
288 struct AISettingsWindow : public Window {
289 CompanyID slot;
290 ScriptConfig *ai_config;
291 int clicked_button;
292 bool clicked_increase;
293 bool clicked_dropdown;
294 bool closing_dropdown;
295 GUITimer timeout;
296 int clicked_row;
297 int line_height;
298 Scrollbar *vscroll;
299 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
300 VisibleSettingsList visible_settings;
301
307 AISettingsWindow(WindowDesc *desc, CompanyID slot) : Window(desc),
308 slot(slot),
309 clicked_button(-1),
310 clicked_dropdown(false),
311 closing_dropdown(false),
312 timeout(0)
313 {
314 this->ai_config = GetConfig(slot);
315
316 this->CreateNestedTree();
317 this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
318 this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
319
320 this->RebuildVisibleSettings();
321 }
322
328 void RebuildVisibleSettings()
329 {
330 visible_settings.clear();
331
332 for (const auto &item : *this->ai_config->GetConfigList()) {
333 bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
334 if (no_hide || _settings_client.gui.ai_developer_tools) {
335 visible_settings.push_back(&item);
336 }
337 }
338
339 this->vscroll->SetCount((int)this->visible_settings.size());
340 }
341
342 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
343 {
344 if (widget == WID_AIS_BACKGROUND) {
345 this->line_height = std::max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + padding.height;
346
347 resize->width = 1;
348 resize->height = this->line_height;
349 size->height = 5 * this->line_height;
350 }
351 }
352
353 void DrawWidget(const Rect &r, int widget) const override
354 {
355 if (widget != WID_AIS_BACKGROUND) return;
356
357 ScriptConfig *config = this->ai_config;
358 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
359 int i = 0;
360 for (; !this->vscroll->IsVisible(i); i++) it++;
361
362 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
363 bool rtl = _current_text_dir == TD_RTL;
364 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
365 Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
366
367 int y = r.top;
368 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
369 int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
370 for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
371 const ScriptConfigItem &config_item = **it;
372 int current_value = config->GetSetting((config_item).name);
373 bool editable = this->IsEditableItem(config_item);
374
375 StringID str;
376 TextColour colour;
377 uint idx = 0;
378 if (StrEmpty(config_item.description)) {
379 if (!strcmp(config_item.name, "start_date")) {
380 /* Build-in translation */
381 str = STR_AI_SETTINGS_START_DELAY;
382 colour = TC_LIGHT_BLUE;
383 } else {
384 str = STR_JUST_STRING;
385 colour = TC_ORANGE;
386 }
387 } else {
388 str = STR_AI_SETTINGS_SETTING;
389 colour = TC_LIGHT_BLUE;
390 SetDParamStr(idx++, config_item.description);
391 }
392
393 if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
394 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
395 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
396 } else {
397 if (config_item.complete_labels) {
398 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
399 } else {
400 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);
401 }
402 if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
403 SetDParam(idx++, STR_JUST_RAW_STRING);
404 SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
405 } else {
406 SetDParam(idx++, STR_JUST_INT);
407 SetDParam(idx++, current_value);
408 }
409 }
410
411 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
412 y += this->line_height;
413 }
414 }
415
416 void OnPaint() override
417 {
418 if (this->closing_dropdown) {
419 this->closing_dropdown = false;
420 this->clicked_dropdown = false;
421 }
422 this->DrawWidgets();
423 }
424
425 void OnClick(Point pt, int widget, int click_count) override
426 {
427 switch (widget) {
428 case WID_AIS_BACKGROUND: {
429 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
430 int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
431 if (num >= (int)this->visible_settings.size()) break;
432
433 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
434 for (int i = 0; i < num; i++) it++;
435 const ScriptConfigItem config_item = **it;
436 if (!this->IsEditableItem(config_item)) return;
437
438 if (this->clicked_row != num) {
439 this->CloseChildWindows(WC_QUERY_STRING);
440 this->CloseChildWindows(WC_DROPDOWN_MENU);
441 this->clicked_row = num;
442 this->clicked_dropdown = false;
443 }
444
445 bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
446
447 int x = pt.x - r.left;
448 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
449
450 /* One of the arrows is clicked (or green/red rect in case of bool value) */
451 int old_val = this->ai_config->GetSetting(config_item.name);
452 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
453 if (this->clicked_dropdown) {
454 /* unclick the dropdown */
455 this->CloseChildWindows(WC_DROPDOWN_MENU);
456 this->clicked_dropdown = false;
457 this->closing_dropdown = false;
458 } else {
459 int rel_y = (pt.y - r.top) % this->line_height;
460
461 Rect wi_rect;
462 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
463 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
464 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
465 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
466
467 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
468 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
469 this->clicked_dropdown = true;
470 this->closing_dropdown = false;
471
472 DropDownList list;
473 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
474 list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
475 }
476
477 ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
478 }
479 }
480 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
481 int new_val = old_val;
482 if (bool_item) {
483 new_val = !new_val;
484 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
485 /* Increase button clicked */
486 new_val += config_item.step_size;
487 if (new_val > config_item.max_value) new_val = config_item.max_value;
488 this->clicked_increase = true;
489 } else {
490 /* Decrease button clicked */
491 new_val -= config_item.step_size;
492 if (new_val < config_item.min_value) new_val = config_item.min_value;
493 this->clicked_increase = false;
494 }
495
496 if (new_val != old_val) {
497 this->ai_config->SetSetting(config_item.name, new_val);
498 this->clicked_button = num;
499 this->timeout.SetInterval(150);
500 }
501 } else if (!bool_item && !config_item.complete_labels) {
502 /* Display a query box so users can enter a custom value. */
503 SetDParam(0, old_val);
504 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QSF_NONE);
505 }
506 this->SetDirty();
507 break;
508 }
509
510 case WID_AIS_ACCEPT:
511 this->Close();
512 break;
513
514 case WID_AIS_RESET:
515 this->ai_config->ResetEditableSettings(_game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
516 this->SetDirty();
517 break;
518 }
519 }
520
521 void OnQueryTextFinished(char *str) override
522 {
523 if (StrEmpty(str)) return;
524 int32 value = atoi(str);
525
526 SetValue(value);
527 }
528
529 void OnDropdownSelect(int widget, int index) override
530 {
531 assert(this->clicked_dropdown);
532 SetValue(index);
533 }
534
535 void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
536 {
537 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
538 * the same dropdown button was clicked again, and then not open the dropdown again.
539 * So, we only remember that it was closed, and process it on the next OnPaint, which is
540 * after OnClick. */
541 assert(this->clicked_dropdown);
542 this->closing_dropdown = true;
543 this->SetDirty();
544 }
545
546 void OnResize() override
547 {
548 this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND);
549 }
550
551 void OnRealtimeTick(uint delta_ms) override
552 {
553 if (this->timeout.Elapsed(delta_ms)) {
554 this->clicked_button = -1;
555 this->SetDirty();
556 }
557 }
558
564 void OnInvalidateData(int data = 0, bool gui_scope = true) override
565 {
566 this->RebuildVisibleSettings();
567 this->CloseChildWindows(WC_DROPDOWN_MENU);
568 this->CloseChildWindows(WC_QUERY_STRING);
569 }
570
571 private:
572 bool IsEditableItem(const ScriptConfigItem &config_item) const
573 {
574 return _game_mode == GM_MENU
575 || _game_mode == GM_EDITOR
576 || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot))
577 || (config_item.flags & SCRIPTCONFIG_INGAME) != 0
578 || _settings_client.gui.ai_developer_tools;
579 }
580
581 void SetValue(int value)
582 {
583 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
584 for (int i = 0; i < this->clicked_row; i++) it++;
585 const ScriptConfigItem config_item = **it;
586 if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
587 this->ai_config->SetSetting(config_item.name, value);
588 this->SetDirty();
589 }
590 };
591
593 static const NWidgetPart _nested_ai_settings_widgets[] = {
594 NWidget(NWID_HORIZONTAL),
595 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
596 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
597 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
598 EndContainer(),
599 NWidget(NWID_HORIZONTAL),
600 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIS_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_AIS_SCROLLBAR),
601 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIS_SCROLLBAR),
602 EndContainer(),
603 NWidget(NWID_HORIZONTAL),
604 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
605 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
606 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
607 EndContainer(),
608 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
609 EndContainer(),
610 };
611
613 static WindowDesc _ai_settings_desc(
614 WDP_CENTER, "settings_script", 500, 208,
615 WC_AI_SETTINGS, WC_NONE,
616 0,
617 _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets)
618 );
619
624 static void ShowAISettingsWindow(CompanyID slot)
625 {
626 CloseWindowByClass(WC_AI_LIST);
627 CloseWindowByClass(WC_AI_SETTINGS);
628 new AISettingsWindow(&_ai_settings_desc, slot);
629 }
630
631
633 struct ScriptTextfileWindow : public TextfileWindow {
634 CompanyID slot;
635
636 ScriptTextfileWindow(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
637 {
638 this->OnInvalidateData();
639 }
640
641 void SetStringParameters(int widget) const override
642 {
643 if (widget == WID_TF_CAPTION) {
644 SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
645 SetDParamStr(1, GetConfig(slot)->GetInfo()->GetName());
646 }
647 }
648
649 void OnInvalidateData(int data = 0, bool gui_scope = true) override
650 {
651 const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
652 if (textfile == nullptr) {
653 this->Close();
654 } else {
655 this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
656 }
657 }
658 };
659
665 void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
666 {
667 CloseWindowById(WC_TEXTFILE, file_type);
668 new ScriptTextfileWindow(file_type, slot);
669 }
670
671
673 static const NWidgetPart _nested_ai_config_widgets[] = {
674 NWidget(NWID_HORIZONTAL),
675 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
676 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
677 EndContainer(),
678 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
679 NWidget(NWID_VERTICAL), SetPIP(4, 4, 4),
680 NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
681 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE), SetDataTip(AWV_DECREASE, STR_NULL),
682 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE), SetDataTip(AWV_INCREASE, STR_NULL),
683 NWidget(NWID_SPACER), SetMinimalSize(6, 0),
684 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_NUMBER), SetDataTip(STR_AI_CONFIG_MAX_COMPETITORS, STR_NULL), SetFill(1, 0),
685 EndContainer(),
686 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
687 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_UP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_UP, STR_AI_CONFIG_MOVE_UP_TOOLTIP),
688 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_DOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_DOWN, STR_AI_CONFIG_MOVE_DOWN_TOOLTIP),
689 EndContainer(),
690 EndContainer(),
691 NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPadding(0, 5, 0, 5),
692 NWidget(NWID_HORIZONTAL),
693 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_LIST), SetMinimalSize(288, 112), SetFill(1, 0), SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP), SetScrollbar(WID_AIC_SCROLLBAR),
694 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
695 EndContainer(),
696 EndContainer(),
697 NWidget(NWID_SPACER), SetMinimalSize(0, 9),
698 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
699 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CHANGE_AI, STR_AI_CONFIG_CHANGE_TOOLTIP),
700 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
701 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
702 EndContainer(),
703 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
704 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
705 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
706 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
707 EndContainer(),
708 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 0), SetMinimalSize(279, 0), SetPadding(0, 7, 9, 7), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
709 EndContainer(),
710 };
711
713 static WindowDesc _ai_config_desc(
714 WDP_CENTER, "settings_script_config", 0, 0,
715 WC_GAME_OPTIONS, WC_NONE,
716 0,
717 _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets)
718 );
719
723 struct AIConfigWindow : public Window {
724 CompanyID selected_slot;
725 int line_height;
726 Scrollbar *vscroll;
727
728 AIConfigWindow() : Window(&_ai_config_desc)
729 {
730 this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
731 this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
732 this->selected_slot = INVALID_COMPANY;
733 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
734 this->vscroll->SetCapacity(nwi->current_y / this->line_height);
735 this->vscroll->SetCount(MAX_COMPANIES);
736 this->OnInvalidateData(0);
737 }
738
739 void Close() override
740 {
741 CloseWindowByClass(WC_AI_LIST);
742 CloseWindowByClass(WC_AI_SETTINGS);
743 this->Window::Close();
744 }
745
746 void SetStringParameters(int widget) const override
747 {
748 switch (widget) {
749 case WID_AIC_NUMBER:
750 SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
751 break;
752 }
753 }
754
755 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
756 {
757 switch (widget) {
758 case WID_AIC_DECREASE:
759 case WID_AIC_INCREASE:
760 *size = maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
761 break;
762
763 case WID_AIC_LIST:
764 this->line_height = FONT_HEIGHT_NORMAL + padding.height;
765 resize->height = this->line_height;
766 size->height = 8 * this->line_height;
767 break;
768 }
769 }
770
776 static bool IsEditable(CompanyID slot)
777 {
778 if (_game_mode != GM_NORMAL) {
779 return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
780 }
781 if (Company::IsValidID(slot)) return false;
782
783 int max_slot = GetGameSettings().difficulty.max_no_competitors;
784 for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
785 if (Company::IsValidHumanID(cid)) max_slot++;
786 }
787 return slot < max_slot;
788 }
789
790 void DrawWidget(const Rect &r, int widget) const override
791 {
792 switch (widget) {
793 case WID_AIC_LIST: {
794 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
795 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
796 StringID text;
797
798 if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
799 text = STR_AI_CONFIG_HUMAN_PLAYER;
800 } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
801 SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
802 text = STR_JUST_RAW_STRING;
803 } else {
804 text = STR_AI_CONFIG_RANDOM_AI;
805 }
806 DrawString(tr, text,
807 (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
808 tr.top += this->line_height;
809 }
810 break;
811 }
812 }
813 }
814
815 void OnClick(Point pt, int widget, int click_count) override
816 {
817 if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
818 if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == nullptr) return;
819
820 ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
821 return;
822 }
823
824 switch (widget) {
825 case WID_AIC_DECREASE:
826 case WID_AIC_INCREASE: {
827 int new_value;
828 if (widget == WID_AIC_DECREASE) {
829 new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
830 } else {
831 new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
832 }
833 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
834 break;
835 }
836
837 case WID_AIC_LIST: { // Select a slot
838 this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
839 this->InvalidateData();
840 if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
841 break;
842 }
843
844 case WID_AIC_MOVE_UP:
845 if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
846 Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
847 this->selected_slot--;
848 this->vscroll->ScrollTowards(this->selected_slot);
849 this->InvalidateData();
850 }
851 break;
852
853 case WID_AIC_MOVE_DOWN:
854 if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
855 Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
856 this->selected_slot++;
857 this->vscroll->ScrollTowards(this->selected_slot);
858 this->InvalidateData();
859 }
860 break;
861
862 case WID_AIC_CHANGE: // choose other AI
863 ShowAIListWindow((CompanyID)this->selected_slot);
864 break;
865
866 case WID_AIC_CONFIGURE: // change the settings for an AI
867 ShowAISettingsWindow((CompanyID)this->selected_slot);
868 break;
869
870 case WID_AIC_CLOSE:
871 this->Close();
872 break;
873
874 case WID_AIC_CONTENT_DOWNLOAD:
875 if (!_network_available) {
876 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
877 } else {
878 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI);
879 }
880 break;
881 }
882 }
883
889 void OnInvalidateData(int data = 0, bool gui_scope = true) override
890 {
891 if (!IsEditable(this->selected_slot)) {
892 this->selected_slot = INVALID_COMPANY;
893 }
894
895 if (!gui_scope) return;
896
897 this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
898 this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
899 this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
900 this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
901 this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
902 this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
903
904 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
905 this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == nullptr));
906 }
907 }
908 };
909
911 void ShowAIConfigWindow()
912 {
913 CloseWindowByClass(WC_GAME_OPTIONS);
914 new AIConfigWindow();
915 }
916
925 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
926 {
927 /* Dead scripts are indicated with red background and
928 * paused scripts are indicated with yellow background. */
929 Colours colour = dead ? COLOUR_RED :
930 (paused ? COLOUR_YELLOW : COLOUR_GREY);
931 if (button.colour != colour) {
932 button.colour = colour;
933 return true;
934 }
935 return false;
936 }
937
941 struct AIDebugWindow : public Window {
942 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
943
944 static CompanyID ai_debug_company;
945 int redraw_timer;
946 int last_vscroll_pos;
947 bool autoscroll;
948 bool show_break_box;
949 static bool break_check_enabled;
950 static char break_string[MAX_BREAK_STR_STRING_LENGTH];
951 QueryString break_editbox;
952 static StringFilter break_string_filter;
953 static bool case_sensitive_break_check;
954 int highlight_row;
955 Scrollbar *vscroll;
956
957 ScriptLog::LogData *GetLogPointer() const
958 {
959 if (ai_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
960 return (ScriptLog::LogData *)Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
961 }
962
967 bool IsDead() const
968 {
969 if (ai_debug_company == OWNER_DEITY) {
970 GameInstance *game = Game::GetInstance();
971 return game == nullptr || game->IsDead();
972 }
973 return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
974 }
975
981 bool IsValidDebugCompany(CompanyID company) const
982 {
983 switch (company) {
984 case INVALID_COMPANY: return false;
985 case OWNER_DEITY: return Game::GetInstance() != nullptr;
986 default: return Company::IsValidAiID(company);
987 }
988 }
989
994 void SelectValidDebugCompany()
995 {
996 /* Check if the currently selected company is still active. */
997 if (this->IsValidDebugCompany(ai_debug_company)) return;
998
999 ai_debug_company = INVALID_COMPANY;
1000
1001 for (const Company *c : Company::Iterate()) {
1002 if (c->is_ai) {
1003 ChangeToAI(c->index);
1004 return;
1005 }
1006 }
1007
1008 /* If no AI is available, see if there is a game script. */
1009 if (Game::GetInstance() != nullptr) ChangeToAI(OWNER_DEITY);
1010 }
1011
1017 AIDebugWindow(WindowDesc *desc, WindowNumber number) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
1018 {
1019 this->CreateNestedTree();
1020 this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
1021 this->show_break_box = _settings_client.gui.ai_developer_tools;
1022 this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
1023 this->FinishInitNested(number);
1024
1025 if (!this->show_break_box) break_check_enabled = false;
1026
1027 this->last_vscroll_pos = 0;
1028 this->autoscroll = true;
1029 this->highlight_row = -1;
1030
1031 this->querystrings[WID_AID_BREAK_STR_EDIT_BOX] = &this->break_editbox;
1032
1033 SetWidgetsDisabledState(!this->show_break_box, WID_AID_BREAK_STR_ON_OFF_BTN, WID_AID_BREAK_STR_EDIT_BOX, WID_AID_MATCH_CASE_BTN, WIDGET_LIST_END);
1034
1035 /* Restore the break string value from static variable */
1036 this->break_editbox.text.Assign(this->break_string);
1037
1038 this->SelectValidDebugCompany();
1039 this->InvalidateData(-1);
1040 }
1041
1042 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1043 {
1044 if (widget == WID_AID_LOG_PANEL) {
1045 resize->height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
1046 size->height = 14 * resize->height + WidgetDimensions::scaled.framerect.Vertical();
1047 }
1048 }
1049
1050 void OnPaint() override
1051 {
1052 this->SelectValidDebugCompany();
1053
1054 /* Draw standard stuff */
1055 this->DrawWidgets();
1056
1057 if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
1058
1059 bool dirty = false;
1060
1061 /* Paint the company icons */
1062 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1063 NWidgetCore *button = this->GetWidget<NWidgetCore>(i + WID_AID_COMPANY_BUTTON_START);
1064
1065 bool valid = Company::IsValidAiID(i);
1066
1067 /* Check whether the validity of the company changed */
1068 dirty |= (button->IsDisabled() == valid);
1069
1070 /* Mark dead/paused AIs by setting the background colour. */
1071 bool dead = valid && Company::Get(i)->ai_instance->IsDead();
1072 bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
1073 /* Re-paint if the button was updated.
1074 * (note that it is intentional that SetScriptButtonColour is always called) */
1075 dirty |= SetScriptButtonColour(*button, dead, paused);
1076
1077 /* Draw company icon only for valid AI companies */
1078 if (!valid) continue;
1079
1080 byte offset = (i == ai_debug_company) ? 1 : 0;
1081 DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
1082 }
1083
1084 /* Set button colour for Game Script. */
1085 GameInstance *game = Game::GetInstance();
1086 bool valid = game != nullptr;
1087 bool dead = valid && game->IsDead();
1088 bool paused = valid && game->IsPaused();
1089
1090 NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_AID_SCRIPT_GAME);
1091 dirty |= (button->IsDisabled() == valid) || SetScriptButtonColour(*button, dead, paused);
1092
1093 if (dirty) this->InvalidateData(-1);
1094
1095 /* If there are no active companies, don't display anything else. */
1096 if (ai_debug_company == INVALID_COMPANY) return;
1097
1098 ScriptLog::LogData *log = this->GetLogPointer();
1099
1100 int scroll_count = (log == nullptr) ? 0 : log->used;
1101 if (this->vscroll->GetCount() != scroll_count) {
1102 this->vscroll->SetCount(scroll_count);
1103
1104 /* We need a repaint */
1105 this->SetWidgetDirty(WID_AID_SCROLLBAR);
1106 }
1107
1108 if (log == nullptr) return;
1109
1110 /* Detect when the user scrolls the window. Enable autoscroll when the
1111 * bottom-most line becomes visible. */
1112 if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
1113 this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
1114 }
1115 if (this->autoscroll) {
1116 int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1117 if (this->vscroll->SetPosition(scroll_pos)) {
1118 /* We need a repaint */
1119 this->SetWidgetDirty(WID_AID_SCROLLBAR);
1120 this->SetWidgetDirty(WID_AID_LOG_PANEL);
1121 }
1122 }
1123 this->last_vscroll_pos = this->vscroll->GetPosition();
1124 }
1125
1126 void SetStringParameters(int widget) const override
1127 {
1128 switch (widget) {
1129 case WID_AID_NAME_TEXT:
1130 if (ai_debug_company == OWNER_DEITY) {
1131 const GameInfo *info = Game::GetInfo();
1132 assert(info != nullptr);
1133 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1134 SetDParamStr(1, info->GetName());
1135 SetDParam(2, info->GetVersion());
1136 } else if (ai_debug_company == INVALID_COMPANY || !Company::IsValidAiID(ai_debug_company)) {
1137 SetDParam(0, STR_EMPTY);
1138 } else {
1139 const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
1140 assert(info != nullptr);
1141 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1142 SetDParamStr(1, info->GetName());
1143 SetDParam(2, info->GetVersion());
1144 }
1145 break;
1146 }
1147 }
1148
1149 void DrawWidget(const Rect &r, int widget) const override
1150 {
1151 if (ai_debug_company == INVALID_COMPANY) return;
1152
1153 switch (widget) {
1154 case WID_AID_LOG_PANEL: {
1155 ScriptLog::LogData *log = this->GetLogPointer();
1156 if (log == nullptr) return;
1157
1158 Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
1159 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1160 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1161 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1162 if (log->lines[pos] == nullptr) break;
1163
1164 TextColour colour;
1165 switch (log->type[pos]) {
1166 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
1167 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED; break;
1168 case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
1169 case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
1170 case ScriptLog::LOG_ERROR: colour = TC_RED; break;
1171 default: colour = TC_BLACK; break;
1172 }
1173
1174 /* Check if the current line should be highlighted */
1175 if (pos == this->highlight_row) {
1176 GfxFillRect(br.left, tr.top, br.right, tr.top + this->resize.step_height - 1, PC_BLACK);
1177 if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
1178 }
1179
1180 DrawString(tr, log->lines[pos], colour, SA_LEFT | SA_FORCE);
1181 tr.top += this->resize.step_height;
1182 }
1183 break;
1184 }
1185 }
1186 }
1187
1192 void ChangeToAI(CompanyID show_ai)
1193 {
1194 if (!this->IsValidDebugCompany(show_ai)) return;
1195
1196 ai_debug_company = show_ai;
1197
1198 this->highlight_row = -1; // The highlight of one AI make little sense for another AI.
1199
1200 /* Close AI settings window to prevent confusion */
1201 CloseWindowByClass(WC_AI_SETTINGS);
1202
1203 this->InvalidateData(-1);
1204
1205 this->autoscroll = true;
1206 this->last_vscroll_pos = this->vscroll->GetPosition();
1207 }
1208
1209 void OnClick(Point pt, int widget, int click_count) override
1210 {
1211 /* Also called for hotkeys, so check for disabledness */
1212 if (this->IsWidgetDisabled(widget)) return;
1213
1214 /* Check which button is clicked */
1215 if (IsInsideMM(widget, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END + 1)) {
1216 ChangeToAI((CompanyID)(widget - WID_AID_COMPANY_BUTTON_START));
1217 }
1218
1219 switch (widget) {
1220 case WID_AID_SCRIPT_GAME:
1221 ChangeToAI(OWNER_DEITY);
1222 break;
1223
1224 case WID_AID_RELOAD_TOGGLE:
1225 if (ai_debug_company == OWNER_DEITY) break;
1226 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1227 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, ai_debug_company, CRR_MANUAL, INVALID_CLIENT_ID);
1228 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, ai_debug_company, CRR_NONE, INVALID_CLIENT_ID);
1229 break;
1230
1231 case WID_AID_SETTINGS:
1232 ShowAISettingsWindow(ai_debug_company);
1233 break;
1234
1235 case WID_AID_BREAK_STR_ON_OFF_BTN:
1236 this->break_check_enabled = !this->break_check_enabled;
1237 this->InvalidateData(-1);
1238 break;
1239
1240 case WID_AID_MATCH_CASE_BTN:
1241 this->case_sensitive_break_check = !this->case_sensitive_break_check;
1242 this->InvalidateData(-1);
1243 break;
1244
1245 case WID_AID_CONTINUE_BTN:
1246 /* Unpause current AI / game script and mark the corresponding script button dirty. */
1247 if (!this->IsDead()) {
1248 if (ai_debug_company == OWNER_DEITY) {
1249 Game::Unpause();
1250 } else {
1251 AI::Unpause(ai_debug_company);
1252 }
1253 }
1254
1255 /* If the last AI/Game Script is unpaused, unpause the game too. */
1256 if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
1257 bool all_unpaused = !Game::IsPaused();
1258 if (all_unpaused) {
1259 for (const Company *c : Company::Iterate()) {
1260 if (c->is_ai && AI::IsPaused(c->index)) {
1261 all_unpaused = false;
1262 break;
1263 }
1264 }
1265 if (all_unpaused) {
1266 /* All scripts have been unpaused => unpause the game. */
1267 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, false);
1268 }
1269 }
1270 }
1271
1272 this->highlight_row = -1;
1273 this->InvalidateData(-1);
1274 break;
1275 }
1276 }
1277
1278 void OnEditboxChanged(int wid) override
1279 {
1280 if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
1281 /* Save the current string to static member so it can be restored next time the window is opened. */
1282 strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
1283 break_string_filter.SetFilterTerm(this->break_string);
1284 }
1285 }
1286
1293 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1294 {
1295 /* If the log message is related to the active company tab, check the break string.
1296 * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1297 if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
1298 /* Get the log instance of the active company */
1299 ScriptLog::LogData *log = this->GetLogPointer();
1300
1301 if (log != nullptr) {
1302 this->break_string_filter.ResetState();
1303 this->break_string_filter.AddLine(log->lines[log->pos]);
1304 if (this->break_string_filter.GetState()) {
1305 /* Pause execution of script. */
1306 if (!this->IsDead()) {
1307 if (ai_debug_company == OWNER_DEITY) {
1308 Game::Pause();
1309 } else {
1310 AI::Pause(ai_debug_company);
1311 }
1312 }
1313
1314 /* Pause the game. */
1315 if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
1316 Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
1317 }
1318
1319 /* Highlight row that matched */
1320 this->highlight_row = log->pos;
1321 }
1322 }
1323 }
1324
1325 if (!gui_scope) return;
1326
1327 this->SelectValidDebugCompany();
1328
1329 ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
1330 this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
1331
1332 /* Update company buttons */
1333 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1334 this->SetWidgetDisabledState(i + WID_AID_COMPANY_BUTTON_START, !Company::IsValidAiID(i));
1335 this->SetWidgetLoweredState(i + WID_AID_COMPANY_BUTTON_START, ai_debug_company == i);
1336 }
1337
1338 this->SetWidgetDisabledState(WID_AID_SCRIPT_GAME, Game::GetGameInstance() == nullptr);
1339 this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
1340
1341 this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
1342 this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
1343
1344 this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
1345 extern CompanyID _local_company;
1346 this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY || ai_debug_company == _local_company);
1347 this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
1348 (ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
1349 }
1350
1351 void OnResize() override
1352 {
1353 this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL, WidgetDimensions::scaled.framerect.Vertical());
1354 }
1355
1356 static HotkeyList hotkeys;
1357 };
1358
1359 CompanyID AIDebugWindow::ai_debug_company = INVALID_COMPANY;
1360 char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
1361 bool AIDebugWindow::break_check_enabled = true;
1362 bool AIDebugWindow::case_sensitive_break_check = false;
1363 StringFilter AIDebugWindow::break_string_filter(&AIDebugWindow::case_sensitive_break_check);
1364
1366 NWidgetBase *MakeCompanyButtonRowsAIDebug(int *biggest_index)
1367 {
1368 return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, COLOUR_GREY, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
1369 }
1370
1376 static EventState AIDebugGlobalHotkeys(int hotkey)
1377 {
1378 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1379 Window *w = ShowAIDebugWindow(INVALID_COMPANY);
1380 if (w == nullptr) return ES_NOT_HANDLED;
1381 return w->OnHotkey(hotkey);
1382 }
1383
1384 static Hotkey aidebug_hotkeys[] = {
1385 Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
1386 Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
1387 Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
1388 Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
1389 Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
1390 Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
1391 Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
1392 Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
1393 Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
1394 Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
1395 Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
1396 Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
1397 Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
1398 Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
1399 Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
1400 Hotkey('S', "settings", WID_AID_SETTINGS),
1401 Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
1402 Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
1403 Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
1404 Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
1405 Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
1406 Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
1407 HOTKEY_LIST_END
1408 };
1409 HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
1410
1412 static const NWidgetPart _nested_ai_debug_widgets[] = {
1413 NWidget(NWID_HORIZONTAL),
1414 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1415 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1416 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1417 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1418 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1419 EndContainer(),
1420 NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_VIEW),
1421 NWidgetFunction(MakeCompanyButtonRowsAIDebug), SetPadding(0, 2, 1, 2),
1422 EndContainer(),
1423 NWidget(NWID_HORIZONTAL),
1424 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_SCRIPT_GAME), SetMinimalSize(100, 20), SetResize(1, 0), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
1425 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_AI_DEBUG_NAME_TOOLTIP),
1426 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1427 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1428 EndContainer(),
1429 NWidget(NWID_HORIZONTAL),
1430 NWidget(NWID_VERTICAL),
1431 /* Log panel */
1432 NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_LOG_PANEL), SetMinimalSize(287, 180), SetResize(1, 1), SetScrollbar(WID_AID_SCROLLBAR),
1433 EndContainer(),
1434 /* Break string widgets */
1435 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_AID_BREAK_STRING_WIDGETS),
1436 NWidget(NWID_HORIZONTAL),
1437 NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_AID_BREAK_STR_ON_OFF_BTN), SetFill(0, 1), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
1438 NWidget(WWT_PANEL, COLOUR_GREY),
1439 NWidget(NWID_HORIZONTAL),
1440 NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
1441 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_AID_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),
1442 EndContainer(),
1443 EndContainer(),
1444 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
1445 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
1446 EndContainer(),
1447 EndContainer(),
1448 EndContainer(),
1449 NWidget(NWID_VERTICAL),
1450 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AID_SCROLLBAR),
1451 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1452 EndContainer(),
1453 EndContainer(),
1454 };
1455
1457 static WindowDesc _ai_debug_desc(
1458 WDP_AUTO, "script_debug", 600, 450,
1459 WC_AI_DEBUG, WC_NONE,
1460 0,
1461 _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets),
1462 &AIDebugWindow::hotkeys
1463 );
1464
1469 Window *ShowAIDebugWindow(CompanyID show_company)
1470 {
1471 if (!_networking || _network_server) {
1472 AIDebugWindow *w = (AIDebugWindow *)BringWindowToFrontById(WC_AI_DEBUG, 0);
1473 if (w == nullptr) w = new AIDebugWindow(&_ai_debug_desc, 0);
1474 if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
1475 return w;
1476 } else {
1477 ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
1478 }
1479
1480 return nullptr;
1481 }
1482
1486 void InitializeAIGui()
1487 {
1488 AIDebugWindow::ai_debug_company = INVALID_COMPANY;
1489 }
1490
1492 void ShowAIDebugWindowIfAIError()
1493 {
1494 /* Network clients can't debug AIs. */
1495 if (_networking && !_network_server) return;
1496
1497 for (const Company *c : Company::Iterate()) {
1498 if (c->is_ai && c->ai_instance->IsDead()) {
1499 ShowAIDebugWindow(c->index);
1500 break;
1501 }
1502 }
1503
1504 GameInstance *g = Game::GetGameInstance();
1505 if (g != nullptr && g->IsDead()) {
1506 ShowAIDebugWindow(OWNER_DEITY);
1507 }
1508 }
MakeCompanyButtonRows
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3323
ShowAISettingsWindow
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
Definition: ai_gui.cpp:624
WID_AIL_ACCEPT
@ WID_AIL_ACCEPT
Accept button.
Definition: ai_widget.h:22
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:3254
IsInsideMM
static 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:230
Game::IsPaused
static bool IsPaused()
Checks if the Game Script is paused.
Definition: game_core.cpp:141
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:395
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
AIDebugWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp:1042
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1261
Game::GetGameInstance
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
Definition: game.hpp:75
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:338
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
AIDebugWindow::AIDebugWindow
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
Definition: ai_gui.cpp:1017
ScriptInfo::GetAuthor
const char * GetAuthor() const
Get the Author of the script.
Definition: script_info.hpp:50
AISettingsWindow::timeout
GUITimer timeout
Timeout for unclicking the button.
Definition: ai_gui.cpp:295
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition: company_type.h:63
AIDebugWindow::redraw_timer
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
Definition: ai_gui.cpp:945
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
MakeCompanyButtonRowsAIDebug
NWidgetBase * MakeCompanyButtonRowsAIDebug(int *biggest_index)
Make a number of rows with buttons for each company for the AI debug window.
Definition: ai_gui.cpp:1366
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
AIListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp:112
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:22
WID_AIS_RESET
@ WID_AIS_RESET
Reset button.
Definition: ai_widget.h:32
_nested_ai_list_widgets
static const NWidgetPart _nested_ai_list_widgets[]
Widgets for the AI list window.
Definition: ai_gui.cpp:246
AIDebugWindow::SelectValidDebugCompany
void SelectValidDebugCompany()
Ensure that ai_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
Definition: ai_gui.cpp:994
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:669
AISettingsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:353
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1143
WID_AIC_NUMBER
@ WID_AIC_NUMBER
Number of AIs.
Definition: ai_widget.h:40
WID_AID_BREAK_STR_ON_OFF_BTN
@ WID_AID_BREAK_STR_ON_OFF_BTN
Enable breaking on string.
Definition: ai_widget.h:64
AIListWindow
Window that let you choose an available AI.
Definition: ai_gui.cpp:60
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
WID_AIC_DECREASE
@ WID_AIC_DECREASE
Decrease the number of AIs.
Definition: ai_widget.h:38
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:46
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
AISettingsWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: ai_gui.cpp:535
WID_AID_RELOAD_TOGGLE
@ WID_AID_RELOAD_TOGGLE
Reload button.
Definition: ai_widget.h:58
WID_AIC_SCROLLBAR
@ WID_AIC_SCROLLBAR
Scrollbar to scroll through the selected AIs.
Definition: ai_widget.h:42
AISettingsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:546
AIDebugWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:1351
WID_AIC_CONFIGURE
@ WID_AIC_CONFIGURE
Change AI settings button.
Definition: ai_widget.h:46
WID_AIC_TEXTFILE
@ WID_AIC_TEXTFILE
Open AI readme, changelog (+1) or license (+2).
Definition: ai_widget.h:48
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:70
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
AIDebugWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: ai_gui.cpp:1278
AIDebugGlobalHotkeys
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
Definition: ai_gui.cpp:1376
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:780
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
AIConfigWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: ai_gui.cpp:815
AISettingsWindow::clicked_button
int clicked_button
The button we clicked.
Definition: ai_gui.cpp:291
ScriptConfigItem::labels
LabelMapping * labels
Text labels for the integer values.
Definition: script_config.hpp:48
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
AIDebugWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: ai_gui.cpp:1050
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
_ai_list_desc
static WindowDesc _ai_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_AI_LIST, WC_NONE, 0, _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets))
Window definition for the ai list window.
Game::GetInfo
static class GameInfo * GetInfo()
Get the current GameInfo.
Definition: game.hpp:80
AIDebugWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:1293
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:99
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
AIDebugWindow::break_string_filter
static StringFilter break_string_filter
Log filter for break.
Definition: ai_gui.cpp:952
ScriptTextfileWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:649
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
AIDebugWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: ai_gui.cpp:1209
ShowNetworkContentListWindow
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
Definition: network_content_gui.cpp:1126
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
WID_AIL_SCROLLBAR
@ WID_AIL_SCROLLBAR
Scrollbar next to the AI list.
Definition: ai_widget.h:20
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:586
_nested_ai_config_widgets
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
Definition: ai_gui.cpp:673
ai_gui.hpp
ShowAIDebugWindowIfAIError
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: ai_gui.cpp:1492
valid
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
Definition: newgrf_station.cpp:248
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
ScriptInfo::GetURL
const char * GetURL() const
Get the website for this script.
Definition: script_info.hpp:85
WID_AID_VIEW
@ WID_AID_VIEW
The row of company buttons.
Definition: ai_widget.h:54
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:427
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:149
AIListWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: ai_gui.cpp:64
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
AIDebugWindow::MAX_BREAK_STR_STRING_LENGTH
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
Definition: ai_gui.cpp:942
WID_AID_SETTINGS
@ WID_AID_SETTINGS
Settings button.
Definition: ai_widget.h:56
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
Game::Unpause
static void Unpause()
Resume execution of the Game Script.
Definition: game_core.cpp:136
AISettingsWindow::VisibleSettingsList
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition: ai_gui.cpp:299
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2353
WID_AIS_ACCEPT
@ WID_AIS_ACCEPT
Accept button.
Definition: ai_widget.h:31
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
WID_AID_MATCH_CASE_BTN
@ WID_AID_MATCH_CASE_BTN
Checkbox to use match caching or not.
Definition: ai_widget.h:66
WID_AIC_MOVE_UP
@ WID_AIC_MOVE_UP
Move up button.
Definition: ai_widget.h:43
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:30
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF changelog.
Definition: textfile_type.h:18
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:634
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:136
ScriptInfo::GetDescription
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:65
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
SCRIPTCONFIG_BOOLEAN
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:28
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:39
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
AIConfigWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp:755
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:257
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:789
WID_AIS_SCROLLBAR
@ WID_AIS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: ai_widget.h:30
ai.hpp
ai_info.hpp
AIDebugWindow::highlight_row
int highlight_row
The output row that matches the given string, or -1.
Definition: ai_gui.cpp:954
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
AIListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:123
AIDebugWindow::last_vscroll_pos
int last_vscroll_pos
Last position of the scrolling.
Definition: ai_gui.cpp:946
GetGameSettings
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition: settings_type.h:628
AISettingsWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: ai_gui.cpp:521
WindowDesc
High level window description.
Definition: window_gui.h:102
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:49
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:135
AIConfigWindow::IsEditable
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Definition: ai_gui.cpp:776
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
WID_AIL_CANCEL
@ WID_AIL_CANCEL
Cancel button.
Definition: ai_widget.h:23
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI/GS developer tools
Definition: settings_type.h:193
WID_AIC_MOVE_DOWN
@ WID_AIC_MOVE_DOWN
Move down button.
Definition: ai_widget.h:44
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:40
GUITimer
Definition: guitimer_func.h:13
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2570
ShowAIListWindow
void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
Definition: ai_gui.cpp:279
WID_AID_LOG_PANEL
@ WID_AID_LOG_PANEL
Panel where the log is in.
Definition: ai_widget.h:59
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
AISettingsWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: ai_gui.cpp:293
ScriptInfoList
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
Definition: ai.hpp:19
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:660
AIDebugWindow::case_sensitive_break_check
static bool case_sensitive_break_check
Is the matching done case-sensitive.
Definition: ai_gui.cpp:953
AIListWindow::AIListWindow
AIListWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
Definition: ai_gui.cpp:72
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition: fileio_type.h:119
_nested_ai_debug_widgets
static const NWidgetPart _nested_ai_debug_widgets[]
Widgets for the AI debug window.
Definition: ai_gui.cpp:1412
AISettingsWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: ai_gui.cpp:551
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:71
AIConfigWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: ai_gui.cpp:739
AIListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:65
AIListWindow::ChangeAI
void ChangeAI()
Changes the AI of the current slot.
Definition: ai_gui.cpp:176
AIDebugWindow::ai_debug_company
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
Definition: ai_gui.cpp:944
Game::Pause
static void Pause()
Suspends the Game Script and then pause the execution of the script.
Definition: game_core.cpp:131
AIListWindow::info_list
const ScriptInfoList * info_list
The list of Scripts.
Definition: ai_gui.cpp:61
WID_AID_SCROLLBAR
@ WID_AID_SCROLLBAR
Scrollbar of the log panel.
Definition: ai_widget.h:60
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:721
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
AISettingsWindow::slot
CompanyID slot
The currently show company's setting.
Definition: ai_gui.cpp:289
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
AIDebugWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:1149
ai_instance.hpp
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:45
ScriptTextfileWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: ai_gui.cpp:641
WID_AID_COMPANY_BUTTON_START
@ WID_AID_COMPANY_BUTTON_START
Buttons in the VIEW.
Definition: ai_widget.h:61
ScriptInstance::IsDead
bool IsDead() const
Return the "this script died" value.
Definition: script_instance.hpp:153
_ai_settings_desc
static WindowDesc _ai_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_AI_SETTINGS, WC_NONE, 0, _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets))
Window definition for the AI settings window.
AIConfigWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:889
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition: ai_core.cpp:122
AIListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: ai_gui.cpp:103
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1129
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
_nested_ai_settings_widgets
static const NWidgetPart _nested_ai_settings_widgets[]
Widgets for the AI settings window.
Definition: ai_gui.cpp:593
ScriptConfig::SetSetting
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:110
WID_AID_COMPANY_BUTTON_END
@ WID_AID_COMPANY_BUTTON_END
Last possible button in the VIEW.
Definition: ai_widget.h:62
AIConfigWindow::line_height
int line_height
Height of a single AI-name line.
Definition: ai_gui.cpp:725
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
_ai_config_desc
static WindowDesc _ai_config_desc(WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
Window definition for the configure AI window.
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:29
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:30
WID_AIS_BACKGROUND
@ WID_AIS_BACKGROUND
Panel to draw the settings on.
Definition: ai_widget.h:29
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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:1115
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:137
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:192
AISettingsWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: ai_gui.cpp:425
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
WID_AIC_CONTENT_DOWNLOAD
@ WID_AIC_CONTENT_DOWNLOAD
Download content button.
Definition: ai_widget.h:49
AISettingsWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: ai_gui.cpp:294
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
AIDebugWindow::IsValidDebugCompany
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
Definition: ai_gui.cpp:981
ScriptTextfileWindow
Window for displaying the textfile of a AI.
Definition: ai_gui.cpp:633
AIListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:229
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition: company_type.h:57
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
AISettingsWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:298
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
AISettingsWindow::AISettingsWindow
AISettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
Definition: ai_gui.cpp:307
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2539
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:116
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:154
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
AIDebugWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:955
AIDebugWindow::show_break_box
bool show_break_box
Whether the break/debug box is visible.
Definition: ai_gui.cpp:948
TFT_README
@ TFT_README
NewGRF readme.
Definition: textfile_type.h:17
WID_AID_NAME_TEXT
@ WID_AID_NAME_TEXT
Name of the current selected.
Definition: ai_widget.h:55
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:3194
AISettingsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:564
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition: ai_core.cpp:143
AIConfigWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:726
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:197
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition: company_type.h:69
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
ScriptConfig::GetTextfile
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:238
AIDebugWindow
Window with everything an AI prints via ScriptLog.
Definition: ai_gui.cpp:941
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:147
GameInstance
Runtime information about a game script like a pointer to the squirrel vm and the current state.
Definition: game_instance.hpp:16
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition: tcp_content_type.h:20
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:733
TFT_LICENSE
@ TFT_LICENSE
NewGRF license.
Definition: textfile_type.h:19
AIListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: ai_gui.cpp:191
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_AID_CONTINUE_BTN
@ WID_AID_CONTINUE_BTN
Continue button.
Definition: ai_widget.h:67
AIDebugWindow::ChangeToAI
void ChangeToAI(CompanyID show_ai)
Change all settings to select another AI.
Definition: ai_gui.cpp:1192
AIConfigWindow
Window to configure which AIs will start.
Definition: ai_gui.cpp:723
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
WID_AIC_CLOSE
@ WID_AIC_CLOSE
Close window button.
Definition: ai_widget.h:47
WC_AI_DEBUG
@ WC_AI_DEBUG
AI debug window; Window numbers:
Definition: window_type.h:656
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:386
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
AIConfigWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:790
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:414
WID_AID_BREAK_STR_EDIT_BOX
@ WID_AID_BREAK_STR_EDIT_BOX
Edit box for the string to break on.
Definition: ai_widget.h:65
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:455
AISettingsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp:342
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:70
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
AISettingsWindow::visible_settings
VisibleSettingsList visible_settings
List of visible AI settings.
Definition: ai_gui.cpp:300
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
ScriptConfigItem::description
const char * description
The description of the configuration setting.
Definition: script_config.hpp:38
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1095
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
WID_AIL_INFO_BG
@ WID_AIL_INFO_BG
Panel to draw some AI information on.
Definition: ai_widget.h:21
WC_AI_LIST
@ WC_AI_LIST
AI list; Window numbers:
Definition: window_type.h:277
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
ScriptConfig::GetSetting
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Definition: script_config.cpp:103
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:688
AIListWindow::slot
CompanyID slot
The company we're selecting a new Script for.
Definition: ai_gui.cpp:63
AISettingsWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition: ai_gui.cpp:296
WID_AIS_CAPTION
@ WID_AIS_CAPTION
Caption of the window.
Definition: ai_widget.h:28
AIDebugWindow::break_check_enabled
static bool break_check_enabled
Stop an AI when it prints a matching string.
Definition: ai_gui.cpp:949
AIDebugWindow::break_string
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
Definition: ai_gui.cpp:950
WID_AIC_LIST
@ WID_AIC_LIST
List with currently selected AIs.
Definition: ai_widget.h:41
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
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:3271
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
InitializeAIGui
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1486
WID_AID_BREAK_STRING_WIDGETS
@ WID_AID_BREAK_STRING_WIDGETS
The panel to handle the breaking on string.
Definition: ai_widget.h:63
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
WC_AI_SETTINGS
@ WC_AI_SETTINGS
AI settings; Window numbers:
Definition: window_type.h:168
ScriptConfig
Script settings.
Definition: script_config.hpp:59
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:62
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:560
ShowAIDebugWindow
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
Definition: ai_gui.cpp:1469
WID_AID_SCRIPT_GAME
@ WID_AID_SCRIPT_GAME
Game Script button.
Definition: ai_widget.h:57
EventState
EventState
State of handling an event.
Definition: window_type.h:719
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:16
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
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: ai_gui.cpp:925
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:338
ScriptTextfileWindow::slot
CompanyID slot
View the textfile of this CompanyID slot.
Definition: ai_gui.cpp:634
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:1791
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
DifficultySettings::max_no_competitors
byte max_no_competitors
the number of competitors (AIs)
Definition: settings_type.h:78
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
AIConfigWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: ai_gui.cpp:746
AIConfigWindow::selected_slot
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
Definition: ai_gui.cpp:724
WID_AIL_LIST
@ WID_AIL_LIST
The matrix with all available AIs.
Definition: ai_widget.h:19
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition: string_type.h:30
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
WN_GAME_OPTIONS_AI
@ WN_GAME_OPTIONS_AI
AI settings.
Definition: window_type.h:15
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
CommandHelper
Definition: command_func.h:94
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:358
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2427
AISettingsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: ai_gui.cpp:416
AIDebugWindow::break_editbox
QueryString break_editbox
Break editbox.
Definition: ai_gui.cpp:951
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1191
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
WID_AIC_INCREASE
@ WID_AIC_INCREASE
Increase the number of AIs.
Definition: ai_widget.h:39
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:47
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:200
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition: ai_core.cpp:320
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
Definition: ai_gui.cpp:665
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:559
ScriptConfig::Change
void Change(const char *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:19
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
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:76
Window
Data structure for an opened window.
Definition: window_gui.h:213
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
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:326
_ai_debug_desc
static WindowDesc _ai_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_AI_DEBUG, WC_NONE, 0, _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets), &AIDebugWindow::hotkeys)
Window definition for the AI debug window.
AIListWindow::selected
int selected
The currently selected Script.
Definition: ai_gui.cpp:62
Game::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
Definition: game_core.cpp:237
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
ScriptInfo::GetName
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:55
AISettingsWindow
Window for settings the parameters of an AI.
Definition: ai_gui.cpp:288
AIListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:219
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2591
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:241
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:60
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
Window::IsWidgetDisabled
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:350
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:316
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:911
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
Game::GetInstance
static class GameInstance * GetInstance()
Get the current active instance.
Definition: game.hpp:106
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
AISettingsWindow::ai_config
ScriptConfig * ai_config
The configuration we're modifying.
Definition: ai_gui.cpp:290
Company
Definition: company_base.h:117
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:149
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1274
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:36
AIDebugWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: ai_gui.cpp:1126
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
WID_AIL_CAPTION
@ WID_AIL_CAPTION
Caption of the window.
Definition: ai_widget.h:18
ScriptConfigItem::name
const char * name
The name of the configuration setting.
Definition: script_config.hpp:37
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
ScriptInstance::GetLogPointer
void * GetLogPointer()
Get the log pointer of this script.
Definition: script_instance.cpp:318
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
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:49
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
WID_AIC_BACKGROUND
@ WID_AIC_BACKGROUND
Window background.
Definition: ai_widget.h:37
AIDebugWindow::autoscroll
bool autoscroll
Whether automatically scrolling should be enabled or not.
Definition: ai_gui.cpp:947
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
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:604
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:749
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1032
AISettingsWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition: ai_gui.cpp:328
ai_config.hpp
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
WID_AIC_CHANGE
@ WID_AIC_CHANGE
Select another AI button.
Definition: ai_widget.h:45
AISettingsWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: ai_gui.cpp:529
AISettingsWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition: ai_gui.cpp:292
AIDebugWindow::IsDead
bool IsDead() const
Check whether the currently selected AI/GS is dead.
Definition: ai_gui.cpp:967
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
AISettingsWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: ai_gui.cpp:297
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:61