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