OpenTTD Source  1.10.0-RC1
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  }
183  }
184 
185  void OnClick(Point pt, int widget, int click_count) override
186  {
187  switch (widget) {
188  case WID_AIL_LIST: { // Select one of the AIs
189  int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST, 0, this->line_height) - 1;
190  if (sel < (int)this->info_list->size()) {
191  this->selected = sel;
192  this->SetDirty();
193  if (click_count > 1) {
194  this->ChangeAI();
195  delete this;
196  }
197  }
198  break;
199  }
200 
201  case WID_AIL_ACCEPT: {
202  this->ChangeAI();
203  delete this;
204  break;
205  }
206 
207  case WID_AIL_CANCEL:
208  delete this;
209  break;
210  }
211  }
212 
213  void OnResize() override
214  {
215  this->vscroll->SetCapacityFromWidget(this, WID_AIL_LIST);
216  }
217 
223  void OnInvalidateData(int data = 0, bool gui_scope = true) override
224  {
225  if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
226  delete this;
227  return;
228  }
229 
230  if (!gui_scope) return;
231 
232  this->vscroll->SetCount((int)this->info_list->size() + 1);
233 
234  /* selected goes from -1 .. length of ai list - 1. */
235  this->selected = min(this->selected, this->vscroll->GetCount() - 2);
236  }
237 };
238 
242  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
243  NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
244  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
245  EndContainer(),
247  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),
248  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIL_SCROLLBAR),
249  EndContainer(),
251  EndContainer(),
254  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
255  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
256  EndContainer(),
257  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
258  EndContainer(),
259 };
260 
263  WDP_CENTER, "settings_script_list", 200, 234,
265  0,
266  _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets)
267 );
268 
273 static void ShowAIListWindow(CompanyID slot)
274 {
276  new AIListWindow(&_ai_list_desc, slot);
277 }
278 
282 struct AISettingsWindow : public Window {
293  typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
294  VisibleSettingsList visible_settings;
295 
302  slot(slot),
303  clicked_button(-1),
304  clicked_dropdown(false),
305  closing_dropdown(false),
306  timeout(0)
307  {
308  this->ai_config = GetConfig(slot);
309 
310  this->CreateNestedTree();
311  this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
312  this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
313 
314  this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
315 
316  this->RebuildVisibleSettings();
317  }
318 
319  void SetStringParameters(int widget) const override
320  {
321  switch (widget) {
322  case WID_AIS_CAPTION:
323  SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
324  break;
325  }
326  }
327 
334  {
335  visible_settings.clear();
336 
337  ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
338  for (; it != this->ai_config->GetConfigList()->end(); it++) {
339  bool no_hide = (it->flags & SCRIPTCONFIG_DEVELOPER) == 0;
340  if (no_hide || _settings_client.gui.ai_developer_tools) {
341  visible_settings.push_back(&(*it));
342  }
343  }
344 
345  this->vscroll->SetCount((int)this->visible_settings.size());
346  }
347 
348  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
349  {
350  if (widget == WID_AIS_BACKGROUND) {
352 
353  resize->width = 1;
354  resize->height = this->line_height;
355  size->height = 5 * this->line_height;
356  }
357  }
358 
359  void DrawWidget(const Rect &r, int widget) const override
360  {
361  if (widget != WID_AIS_BACKGROUND) return;
362 
363  ScriptConfig *config = this->ai_config;
364  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
365  int i = 0;
366  for (; !this->vscroll->IsVisible(i); i++) it++;
367 
368  bool rtl = _current_text_dir == TD_RTL;
369  uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
370  uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
371  uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
372 
373 
374  int y = r.top;
375  int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
376  int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
377  for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
378  const ScriptConfigItem &config_item = **it;
379  int current_value = config->GetSetting((config_item).name);
380  bool editable = this->IsEditableItem(config_item);
381 
382  StringID str;
383  TextColour colour;
384  uint idx = 0;
385  if (StrEmpty(config_item.description)) {
386  if (!strcmp(config_item.name, "start_date")) {
387  /* Build-in translation */
388  str = STR_AI_SETTINGS_START_DELAY;
389  colour = TC_LIGHT_BLUE;
390  } else {
391  str = STR_JUST_STRING;
392  colour = TC_ORANGE;
393  }
394  } else {
395  str = STR_AI_SETTINGS_SETTING;
396  colour = TC_LIGHT_BLUE;
397  SetDParamStr(idx++, config_item.description);
398  }
399 
400  if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
401  DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
402  SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
403  } else {
404  if (config_item.complete_labels) {
405  DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
406  } else {
407  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);
408  }
409  if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
410  SetDParam(idx++, STR_JUST_RAW_STRING);
411  SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
412  } else {
413  SetDParam(idx++, STR_JUST_INT);
414  SetDParam(idx++, current_value);
415  }
416  }
417 
418  DrawString(text_left, text_right, y + text_y_offset, str, colour);
419  y += this->line_height;
420  }
421  }
422 
423  void OnPaint() override
424  {
425  if (this->closing_dropdown) {
426  this->closing_dropdown = false;
427  this->clicked_dropdown = false;
428  }
429  this->DrawWidgets();
430  }
431 
432  void OnClick(Point pt, int widget, int click_count) override
433  {
434  switch (widget) {
435  case WID_AIS_BACKGROUND: {
436  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
437  int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
438  if (num >= (int)this->visible_settings.size()) break;
439 
440  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
441  for (int i = 0; i < num; i++) it++;
442  const ScriptConfigItem config_item = **it;
443  if (!this->IsEditableItem(config_item)) return;
444 
445  if (this->clicked_row != num) {
447  HideDropDownMenu(this);
448  this->clicked_row = num;
449  this->clicked_dropdown = false;
450  }
451 
452  bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
453 
454  int x = pt.x - wid->pos_x;
455  if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x;
456  x -= 4;
457 
458  /* One of the arrows is clicked (or green/red rect in case of bool value) */
459  int old_val = this->ai_config->GetSetting(config_item.name);
460  if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
461  if (this->clicked_dropdown) {
462  /* unclick the dropdown */
463  HideDropDownMenu(this);
464  this->clicked_dropdown = false;
465  this->closing_dropdown = false;
466  } else {
467  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
468  int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
469 
470  Rect wi_rect;
471  wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
472  wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
473  wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
474  wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
475 
476  /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
477  if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
478  this->clicked_dropdown = true;
479  this->closing_dropdown = false;
480 
481  DropDownList list;
482  for (int i = config_item.min_value; i <= config_item.max_value; i++) {
483  list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
484  }
485 
486  ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
487  }
488  }
489  } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
490  int new_val = old_val;
491  if (bool_item) {
492  new_val = !new_val;
493  } else if (x >= SETTING_BUTTON_WIDTH / 2) {
494  /* Increase button clicked */
495  new_val += config_item.step_size;
496  if (new_val > config_item.max_value) new_val = config_item.max_value;
497  this->clicked_increase = true;
498  } else {
499  /* Decrease button clicked */
500  new_val -= config_item.step_size;
501  if (new_val < config_item.min_value) new_val = config_item.min_value;
502  this->clicked_increase = false;
503  }
504 
505  if (new_val != old_val) {
506  this->ai_config->SetSetting(config_item.name, new_val);
507  this->clicked_button = num;
508  this->timeout.SetInterval(150);
509  }
510  } else if (!bool_item && !config_item.complete_labels) {
511  /* Display a query box so users can enter a custom value. */
512  SetDParam(0, old_val);
513  ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
514  }
515  this->SetDirty();
516  break;
517  }
518 
519  case WID_AIS_ACCEPT:
520  delete this;
521  break;
522 
523  case WID_AIS_RESET:
524  if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
525  this->ai_config->ResetSettings();
526  this->SetDirty();
527  }
528  break;
529  }
530  }
531 
532  void OnQueryTextFinished(char *str) override
533  {
534  if (StrEmpty(str)) return;
535  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
536  for (int i = 0; i < this->clicked_row; i++) it++;
537  const ScriptConfigItem config_item = **it;
538  if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
539  int32 value = atoi(str);
540  this->ai_config->SetSetting(config_item.name, value);
541  this->SetDirty();
542  }
543 
544  void OnDropdownSelect(int widget, int index) override
545  {
546  assert(this->clicked_dropdown);
547  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
548  for (int i = 0; i < this->clicked_row; i++) it++;
549  const ScriptConfigItem config_item = **it;
550  if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
551  this->ai_config->SetSetting(config_item.name, index);
552  this->SetDirty();
553  }
554 
555  void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
556  {
557  /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
558  * the same dropdown button was clicked again, and then not open the dropdown again.
559  * So, we only remember that it was closed, and process it on the next OnPaint, which is
560  * after OnClick. */
561  assert(this->clicked_dropdown);
562  this->closing_dropdown = true;
563  this->SetDirty();
564  }
565 
566  void OnResize() override
567  {
568  this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND);
569  }
570 
571  void OnRealtimeTick(uint delta_ms) override
572  {
573  if (this->timeout.Elapsed(delta_ms)) {
574  this->clicked_button = -1;
575  this->SetDirty();
576  }
577  }
578 
584  void OnInvalidateData(int data = 0, bool gui_scope = true) override
585  {
586  this->RebuildVisibleSettings();
587  HideDropDownMenu(this);
589  }
590 
591 private:
592  bool IsEditableItem(const ScriptConfigItem config_item) const
593  {
594  return _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
595  }
596 };
597 
601  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
602  NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
603  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
604  EndContainer(),
606  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),
607  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIS_SCROLLBAR),
608  EndContainer(),
611  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
612  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
613  EndContainer(),
614  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
615  EndContainer(),
616 };
617 
620  WDP_CENTER, "settings_script", 500, 208,
622  0,
623  _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets)
624 );
625 
631 {
634  new AISettingsWindow(&_ai_settings_desc, slot);
635 }
636 
637 
641 
642  ScriptTextfileWindow(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
643  {
644  this->OnInvalidateData();
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)->GetInfo()->GetName());
652  }
653  }
654 
655  void OnInvalidateData(int data = 0, bool gui_scope = true) override
656  {
657  const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
658  if (textfile == nullptr) {
659  delete this;
660  } else {
661  this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
662  }
663  }
664 };
665 
672 {
673  DeleteWindowById(WC_TEXTFILE, file_type);
674  new ScriptTextfileWindow(file_type, slot);
675 }
676 
677 
681  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
682  NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
683  EndContainer(),
684  NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
685  NWidget(NWID_VERTICAL), SetPIP(4, 4, 4),
686  NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
687  NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE), SetFill(0, 1), SetDataTip(AWV_DECREASE, STR_NULL),
688  NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE), SetFill(0, 1), SetDataTip(AWV_INCREASE, STR_NULL),
690  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),
691  EndContainer(),
693  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),
694  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),
695  EndContainer(),
696  EndContainer(),
697  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPadding(0, 5, 0, 5),
699  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),
700  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
701  EndContainer(),
702  EndContainer(),
704  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetPadding(0, 5, 4, 5),
705  NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetMinimalSize(288, 14), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
706  EndContainer(),
708  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CHANGE, STR_AI_CONFIG_CHANGE_TOOLTIP),
709  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
710  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
711  EndContainer(),
713  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
714  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
715  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
716  EndContainer(),
717  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),
718  EndContainer(),
719 };
720 
723  WDP_CENTER, "settings_script_config", 0, 0,
725  0,
726  _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets)
727 );
728 
732 struct AIConfigWindow : public Window {
736 
737  AIConfigWindow() : Window(&_ai_config_desc)
738  {
739  this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
740  this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
741  this->selected_slot = INVALID_COMPANY;
742  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
743  this->vscroll->SetCapacity(nwi->current_y / this->line_height);
744  this->vscroll->SetCount(MAX_COMPANIES);
745  this->OnInvalidateData(0);
746  }
747 
748  ~AIConfigWindow()
749  {
752  }
753 
754  void SetStringParameters(int widget) const override
755  {
756  switch (widget) {
757  case WID_AIC_NUMBER:
758  SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
759  break;
760  case WID_AIC_CHANGE:
761  switch (selected_slot) {
762  case OWNER_DEITY:
763  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
764  break;
765 
766  case INVALID_COMPANY:
767  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
768  break;
769 
770  default:
771  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
772  break;
773  }
774  break;
775  }
776  }
777 
778  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
779  {
780  switch (widget) {
781  case WID_AIC_GAMELIST:
782  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
783  size->height = 1 * this->line_height;
784  break;
785 
786  case WID_AIC_LIST:
787  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
788  size->height = 8 * this->line_height;
789  break;
790 
791  case WID_AIC_CHANGE: {
792  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
793  Dimension dim = GetStringBoundingBox(STR_AI_CONFIG_CHANGE);
794 
795  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
796  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
797 
798  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
799  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
800 
801  dim.width += padding.width;
802  dim.height += padding.height;
803  *size = maxdim(*size, dim);
804  break;
805  }
806  }
807  }
808 
814  static bool IsEditable(CompanyID slot)
815  {
816  if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
817 
818  if (_game_mode != GM_NORMAL) {
819  return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
820  }
821  if (Company::IsValidID(slot)) return false;
822 
824  for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
825  if (Company::IsValidHumanID(cid)) max_slot++;
826  }
827  return slot < max_slot;
828  }
829 
830  void DrawWidget(const Rect &r, int widget) const override
831  {
832  switch (widget) {
833  case WID_AIC_GAMELIST: {
834  StringID text = STR_AI_CONFIG_NONE;
835 
836  if (GameConfig::GetConfig()->GetInfo() != nullptr) {
837  SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
838  text = STR_JUST_RAW_STRING;
839  }
840 
841  DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
842  (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
843 
844  break;
845  }
846 
847  case WID_AIC_LIST: {
848  int y = r.top;
849  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
850  StringID text;
851 
852  if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
853  text = STR_AI_CONFIG_HUMAN_PLAYER;
854  } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
855  SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
856  text = STR_JUST_RAW_STRING;
857  } else {
858  text = STR_AI_CONFIG_RANDOM_AI;
859  }
860  DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
861  (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
862  y += this->line_height;
863  }
864  break;
865  }
866  }
867  }
868 
869  void OnClick(Point pt, int widget, int click_count) override
870  {
871  if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
872  if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == nullptr) return;
873 
874  ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
875  return;
876  }
877 
878  switch (widget) {
879  case WID_AIC_DECREASE:
880  case WID_AIC_INCREASE: {
881  int new_value;
882  if (widget == WID_AIC_DECREASE) {
883  new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
884  } else {
885  new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
886  }
887  IConsoleSetSetting("difficulty.max_no_competitors", new_value);
888  break;
889  }
890 
891  case WID_AIC_GAMELIST: {
892  this->selected_slot = OWNER_DEITY;
893  this->InvalidateData();
894  if (click_count > 1 && this->selected_slot != INVALID_COMPANY && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)this->selected_slot);
895  break;
896  }
897 
898  case WID_AIC_LIST: { // Select a slot
899  this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
900  this->InvalidateData();
901  if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
902  break;
903  }
904 
905  case WID_AIC_MOVE_UP:
906  if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
907  Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
908  this->selected_slot--;
909  this->vscroll->ScrollTowards(this->selected_slot);
910  this->InvalidateData();
911  }
912  break;
913 
914  case WID_AIC_MOVE_DOWN:
915  if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
916  Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
917  this->selected_slot++;
918  this->vscroll->ScrollTowards(this->selected_slot);
919  this->InvalidateData();
920  }
921  break;
922 
923  case WID_AIC_CHANGE: // choose other AI
924  ShowAIListWindow((CompanyID)this->selected_slot);
925  break;
926 
927  case WID_AIC_CONFIGURE: // change the settings for an AI
928  ShowAISettingsWindow((CompanyID)this->selected_slot);
929  break;
930 
931  case WID_AIC_CLOSE:
932  delete this;
933  break;
934 
936  if (!_network_available) {
937  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
938  } else {
940  }
941  break;
942  }
943  }
944 
950  void OnInvalidateData(int data = 0, bool gui_scope = true) override
951  {
952  if (!IsEditable(this->selected_slot)) {
953  this->selected_slot = INVALID_COMPANY;
954  }
955 
956  if (!gui_scope) return;
957 
958  this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
959  this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
960  this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
961  this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
962  this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
963  this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
964 
965  for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
966  this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == nullptr));
967  }
968  }
969 };
970 
973 {
975  new AIConfigWindow();
976 }
977 
986 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
987 {
988  /* Dead scripts are indicated with red background and
989  * paused scripts are indicated with yellow background. */
990  Colours colour = dead ? COLOUR_RED :
991  (paused ? COLOUR_YELLOW : COLOUR_GREY);
992  if (button.colour != colour) {
993  button.colour = colour;
994  return true;
995  }
996  return false;
997 }
998 
1002 struct AIDebugWindow : public Window {
1003  static const int top_offset;
1004  static const int bottom_offset;
1005 
1006  static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1007 
1011  bool autoscroll;
1013  static bool break_check_enabled;
1014  static char break_string[MAX_BREAK_STR_STRING_LENGTH];
1020 
1021  ScriptLog::LogData *GetLogPointer() const
1022  {
1023  if (ai_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
1024  return (ScriptLog::LogData *)Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1025  }
1026 
1031  bool IsDead() const
1032  {
1033  if (ai_debug_company == OWNER_DEITY) {
1034  GameInstance *game = Game::GetInstance();
1035  return game == nullptr || game->IsDead();
1036  }
1037  return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
1038  }
1039 
1045  bool IsValidDebugCompany(CompanyID company) const
1046  {
1047  switch (company) {
1048  case INVALID_COMPANY: return false;
1049  case OWNER_DEITY: return Game::GetInstance() != nullptr;
1050  default: return Company::IsValidAiID(company);
1051  }
1052  }
1053 
1059  {
1060  /* Check if the currently selected company is still active. */
1061  if (this->IsValidDebugCompany(ai_debug_company)) return;
1062 
1063  ai_debug_company = INVALID_COMPANY;
1064 
1065  for (const Company *c : Company::Iterate()) {
1066  if (c->is_ai) {
1067  ChangeToAI(c->index);
1068  return;
1069  }
1070  }
1071 
1072  /* If no AI is available, see if there is a game script. */
1073  if (Game::GetInstance() != nullptr) ChangeToAI(OWNER_DEITY);
1074  }
1075 
1081  AIDebugWindow(WindowDesc *desc, WindowNumber number) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
1082  {
1083  this->CreateNestedTree();
1084  this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
1085  this->show_break_box = _settings_client.gui.ai_developer_tools;
1086  this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
1087  this->FinishInitNested(number);
1088 
1089  if (!this->show_break_box) break_check_enabled = false;
1090 
1091  this->last_vscroll_pos = 0;
1092  this->autoscroll = true;
1093  this->highlight_row = -1;
1094 
1095  this->querystrings[WID_AID_BREAK_STR_EDIT_BOX] = &this->break_editbox;
1096 
1098 
1099  /* Restore the break string value from static variable */
1100  this->break_editbox.text.Assign(this->break_string);
1101 
1102  this->SelectValidDebugCompany();
1103  this->InvalidateData(-1);
1104  }
1105 
1106  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1107  {
1108  if (widget == WID_AID_LOG_PANEL) {
1109  resize->height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1110  size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1111  }
1112  }
1113 
1114  void OnPaint() override
1115  {
1116  this->SelectValidDebugCompany();
1117 
1118  /* Draw standard stuff */
1119  this->DrawWidgets();
1120 
1121  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
1122 
1123  bool dirty = false;
1124 
1125  /* Paint the company icons */
1126  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1127  NWidgetCore *button = this->GetWidget<NWidgetCore>(i + WID_AID_COMPANY_BUTTON_START);
1128 
1129  bool valid = Company::IsValidAiID(i);
1130 
1131  /* Check whether the validity of the company changed */
1132  dirty |= (button->IsDisabled() == valid);
1133 
1134  /* Mark dead/paused AIs by setting the background colour. */
1135  bool dead = valid && Company::Get(i)->ai_instance->IsDead();
1136  bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
1137  /* Re-paint if the button was updated.
1138  * (note that it is intentional that SetScriptButtonColour is always called) */
1139  dirty |= SetScriptButtonColour(*button, dead, paused);
1140 
1141  /* Draw company icon only for valid AI companies */
1142  if (!valid) continue;
1143 
1144  byte offset = (i == ai_debug_company) ? 1 : 0;
1145  DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
1146  }
1147 
1148  /* Set button colour for Game Script. */
1149  GameInstance *game = Game::GetInstance();
1150  bool valid = game != nullptr;
1151  bool dead = valid && game->IsDead();
1152  bool paused = valid && game->IsPaused();
1153 
1154  NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_AID_SCRIPT_GAME);
1155  dirty |= (button->IsDisabled() == valid) || SetScriptButtonColour(*button, dead, paused);
1156 
1157  if (dirty) this->InvalidateData(-1);
1158 
1159  /* If there are no active companies, don't display anything else. */
1160  if (ai_debug_company == INVALID_COMPANY) return;
1161 
1162  ScriptLog::LogData *log = this->GetLogPointer();
1163 
1164  int scroll_count = (log == nullptr) ? 0 : log->used;
1165  if (this->vscroll->GetCount() != scroll_count) {
1166  this->vscroll->SetCount(scroll_count);
1167 
1168  /* We need a repaint */
1170  }
1171 
1172  if (log == nullptr) return;
1173 
1174  /* Detect when the user scrolls the window. Enable autoscroll when the
1175  * bottom-most line becomes visible. */
1176  if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
1177  this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
1178  }
1179  if (this->autoscroll) {
1180  int scroll_pos = max(0, log->used - this->vscroll->GetCapacity());
1181  if (scroll_pos != this->vscroll->GetPosition()) {
1182  this->vscroll->SetPosition(scroll_pos);
1183 
1184  /* We need a repaint */
1187  }
1188  }
1189  this->last_vscroll_pos = this->vscroll->GetPosition();
1190  }
1191 
1192  void SetStringParameters(int widget) const override
1193  {
1194  switch (widget) {
1195  case WID_AID_NAME_TEXT:
1196  if (ai_debug_company == OWNER_DEITY) {
1197  const GameInfo *info = Game::GetInfo();
1198  assert(info != nullptr);
1199  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1200  SetDParamStr(1, info->GetName());
1201  SetDParam(2, info->GetVersion());
1202  } else if (ai_debug_company == INVALID_COMPANY || !Company::IsValidAiID(ai_debug_company)) {
1203  SetDParam(0, STR_EMPTY);
1204  } else {
1205  const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
1206  assert(info != nullptr);
1207  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1208  SetDParamStr(1, info->GetName());
1209  SetDParam(2, info->GetVersion());
1210  }
1211  break;
1212  }
1213  }
1214 
1215  void DrawWidget(const Rect &r, int widget) const override
1216  {
1217  if (ai_debug_company == INVALID_COMPANY) return;
1218 
1219  switch (widget) {
1220  case WID_AID_LOG_PANEL: {
1221  ScriptLog::LogData *log = this->GetLogPointer();
1222  if (log == nullptr) return;
1223 
1224  int y = this->top_offset;
1225  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1226  int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1227  if (log->lines[pos] == nullptr) break;
1228 
1229  TextColour colour;
1230  switch (log->type[pos]) {
1231  case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
1232  case ScriptLog::LOG_SQ_ERROR: colour = TC_RED; break;
1233  case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
1234  case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
1235  case ScriptLog::LOG_ERROR: colour = TC_RED; break;
1236  default: colour = TC_BLACK; break;
1237  }
1238 
1239  /* Check if the current line should be highlighted */
1240  if (pos == this->highlight_row) {
1241  GfxFillRect(r.left + 1, r.top + y, r.right - 1, r.top + y + this->resize.step_height - WD_PAR_VSEP_NORMAL, PC_BLACK);
1242  if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
1243  }
1244 
1245  DrawString(r.left + 7, r.right - 7, r.top + y, log->lines[pos], colour, SA_LEFT | SA_FORCE);
1246  y += this->resize.step_height;
1247  }
1248  break;
1249  }
1250  }
1251  }
1252 
1257  void ChangeToAI(CompanyID show_ai)
1258  {
1259  if (!this->IsValidDebugCompany(show_ai)) return;
1260 
1261  ai_debug_company = show_ai;
1262 
1263  this->highlight_row = -1; // The highlight of one AI make little sense for another AI.
1264 
1265  /* Close AI settings window to prevent confusion */
1267 
1268  this->InvalidateData(-1);
1269 
1270  this->autoscroll = true;
1271  this->last_vscroll_pos = this->vscroll->GetPosition();
1272  }
1273 
1274  void OnClick(Point pt, int widget, int click_count) override
1275  {
1276  /* Also called for hotkeys, so check for disabledness */
1277  if (this->IsWidgetDisabled(widget)) return;
1278 
1279  /* Check which button is clicked */
1281  ChangeToAI((CompanyID)(widget - WID_AID_COMPANY_BUTTON_START));
1282  }
1283 
1284  switch (widget) {
1285  case WID_AID_SCRIPT_GAME:
1286  ChangeToAI(OWNER_DEITY);
1287  break;
1288 
1289  case WID_AID_RELOAD_TOGGLE:
1290  if (ai_debug_company == OWNER_DEITY) break;
1291  /* First kill the company of the AI, then start a new one. This should start the current AI again */
1292  DoCommandP(0, CCA_DELETE | ai_debug_company << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
1293  DoCommandP(0, CCA_NEW_AI | ai_debug_company << 16, 0, CMD_COMPANY_CTRL);
1294  break;
1295 
1296  case WID_AID_SETTINGS:
1297  ShowAISettingsWindow(ai_debug_company);
1298  break;
1299 
1301  this->break_check_enabled = !this->break_check_enabled;
1302  this->InvalidateData(-1);
1303  break;
1304 
1306  this->case_sensitive_break_check = !this->case_sensitive_break_check;
1307  this->InvalidateData(-1);
1308  break;
1309 
1310  case WID_AID_CONTINUE_BTN:
1311  /* Unpause current AI / game script and mark the corresponding script button dirty. */
1312  if (!this->IsDead()) {
1313  if (ai_debug_company == OWNER_DEITY) {
1314  Game::Unpause();
1315  } else {
1316  AI::Unpause(ai_debug_company);
1317  }
1318  }
1319 
1320  /* If the last AI/Game Script is unpaused, unpause the game too. */
1321  if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
1322  bool all_unpaused = !Game::IsPaused();
1323  if (all_unpaused) {
1324  for (const Company *c : Company::Iterate()) {
1325  if (c->is_ai && AI::IsPaused(c->index)) {
1326  all_unpaused = false;
1327  break;
1328  }
1329  }
1330  if (all_unpaused) {
1331  /* All scripts have been unpaused => unpause the game. */
1332  DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
1333  }
1334  }
1335  }
1336 
1337  this->highlight_row = -1;
1338  this->InvalidateData(-1);
1339  break;
1340  }
1341  }
1342 
1343  void OnEditboxChanged(int wid) override
1344  {
1345  if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
1346  /* Save the current string to static member so it can be restored next time the window is opened. */
1347  strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
1348  break_string_filter.SetFilterTerm(this->break_string);
1349  }
1350  }
1351 
1358  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1359  {
1360  /* If the log message is related to the active company tab, check the break string.
1361  * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1362  if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
1363  /* Get the log instance of the active company */
1364  ScriptLog::LogData *log = this->GetLogPointer();
1365 
1366  if (log != nullptr) {
1367  this->break_string_filter.ResetState();
1368  this->break_string_filter.AddLine(log->lines[log->pos]);
1369  if (this->break_string_filter.GetState()) {
1370  /* Pause execution of script. */
1371  if (!this->IsDead()) {
1372  if (ai_debug_company == OWNER_DEITY) {
1373  Game::Pause();
1374  } else {
1375  AI::Pause(ai_debug_company);
1376  }
1377  }
1378 
1379  /* Pause the game. */
1381  DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
1382  }
1383 
1384  /* Highlight row that matched */
1385  this->highlight_row = log->pos;
1386  }
1387  }
1388  }
1389 
1390  if (!gui_scope) return;
1391 
1392  this->SelectValidDebugCompany();
1393 
1394  ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
1395  this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
1396 
1397  /* Update company buttons */
1398  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1400  this->SetWidgetLoweredState(i + WID_AID_COMPANY_BUTTON_START, ai_debug_company == i);
1401  }
1402 
1404  this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
1405 
1406  this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
1407  this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
1408 
1409  this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
1410  this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY);
1411  this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
1412  (ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
1413  }
1414 
1415  void OnResize() override
1416  {
1417  this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
1418  }
1419 
1420  static HotkeyList hotkeys;
1421 };
1422 
1426 char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
1429 StringFilter AIDebugWindow::break_string_filter(&AIDebugWindow::case_sensitive_break_check);
1430 
1433 {
1434  return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
1435 }
1436 
1443 {
1444  if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1446  if (w == nullptr) return ES_NOT_HANDLED;
1447  return w->OnHotkey(hotkey);
1448 }
1449 
1450 static Hotkey aidebug_hotkeys[] = {
1451  Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
1452  Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
1453  Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
1454  Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
1455  Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
1456  Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
1457  Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
1458  Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
1459  Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
1460  Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
1461  Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
1462  Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
1463  Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
1464  Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
1465  Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
1466  Hotkey('S', "settings", WID_AID_SETTINGS),
1467  Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
1468  Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
1469  Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
1470  Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
1471  Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
1472  Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
1473  HOTKEY_LIST_END
1474 };
1475 HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
1476 
1480  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1481  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1482  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1483  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1484  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1485  EndContainer(),
1486  NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_VIEW),
1488  EndContainer(),
1490  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),
1491  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_AI_DEBUG_NAME_TOOLTIP),
1492  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1493  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1494  EndContainer(),
1497  /* Log panel */
1499  EndContainer(),
1500  /* Break string widgets */
1503  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),
1504  NWidget(WWT_PANEL, COLOUR_GREY),
1506  NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
1507  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),
1508  EndContainer(),
1509  EndContainer(),
1510  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),
1511  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),
1512  EndContainer(),
1513  EndContainer(),
1514  EndContainer(),
1516  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AID_SCROLLBAR),
1517  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1518  EndContainer(),
1519  EndContainer(),
1520 };
1521 
1523 static WindowDesc _ai_debug_desc(
1524  WDP_AUTO, "script_debug", 600, 450,
1526  0,
1527  _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets),
1528  &AIDebugWindow::hotkeys
1529 );
1530 
1536 {
1537  if (!_networking || _network_server) {
1539  if (w == nullptr) w = new AIDebugWindow(&_ai_debug_desc, 0);
1540  if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
1541  return w;
1542  } else {
1543  ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
1544  }
1545 
1546  return nullptr;
1547 }
1548 
1553 {
1554  AIDebugWindow::ai_debug_company = INVALID_COMPANY;
1555 }
1556 
1559 {
1560  /* Network clients can't debug AIs. */
1561  if (_networking && !_network_server) return;
1562 
1563  for (const Company *c : Company::Iterate()) {
1564  if (c->is_ai && c->ai_instance->IsDead()) {
1565  ShowAIDebugWindow(c->index);
1566  break;
1567  }
1568  }
1569 
1571  if (g != nullptr && g->IsDead()) {
1573  }
1574 }
EventState
State of handling an event.
Definition: window_type.h:717
Colours colour
Colour of this widget.
Definition: widget_type.h:301
GUITimer timeout
Timeout for unclicking the button.
Definition: ai_gui.cpp:289
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:280
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:333
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:1215
bool autoscroll
Whether automatically scrolling should be enabled or not.
Definition: ai_gui.cpp:1011
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:735
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:284
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:986
static bool break_check_enabled
Stop an AI when it prints a matching string.
Definition: ai_gui.cpp:1013
static void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
Definition: ai_gui.cpp:273
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:1358
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:329
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:1019
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:719
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:655
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:1009
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:599
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
Definition: ai_gui.cpp:1008
static const int top_offset
Offset of the text at the top of the WID_AID_LOG_PANEL.
Definition: ai_gui.cpp:1003
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:640
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:1018
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1552
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:1045
int max_value
The maximal value this configuration setting can have.
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:972
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:1004
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:359
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:185
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:566
Scrollbar to scroll through all settings.
Definition: ai_widget.h:30
int last_vscroll_pos
Last position of the scrolling.
Definition: ai_gui.cpp:1010
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:1442
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: ai_gui.cpp:1558
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:1058
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:555
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:285
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:1831
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:1106
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:1847
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:3337
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1860
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:223
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:288
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:283
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: ai_gui.cpp:532
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:301
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:432
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: ai_gui.cpp:1343
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:177
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:79
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:1274
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:734
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:571
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:1478
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:754
Simple depressed panel.
Definition: widget_type.h:48
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
Definition: ai_gui.cpp:1081
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:732
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
Definition: ai_gui.cpp:679
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:1015
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:1016
Frame.
Definition: widget_type.h:58
bool clicked_dropdown
Whether the dropdown is open.
Definition: ai_gui.cpp:287
Center the window.
Definition: window_gui.h:155
int clicked_row
The clicked row of settings.
Definition: ai_gui.cpp:290
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:282
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:636
Window with everything an AI prints via ScriptLog.
Definition: ai_gui.cpp:1002
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:536
#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:1432
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:1178
Delete a company.
Definition: company_type.h:67
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:204
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:348
#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:1114
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
Definition: ai_gui.cpp:1535
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:838
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:778
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:1165
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
Definition: ai_gui.cpp:1014
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:423
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:319
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:292
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:378
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:639
void ChangeToAI(CompanyID show_ai)
Change all settings to select another AI.
Definition: ai_gui.cpp:1257
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
Definition: ai_gui.cpp:733
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:294
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:584
bool show_break_box
Whether the break/debug box is visible.
Definition: ai_gui.cpp:1012
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:671
static const NWidgetPart _nested_ai_list_widgets[]
Widgets for the AI list window.
Definition: ai_gui.cpp:240
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:1415
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:950
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:318
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:1192
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:286
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:830
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:869
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:291
Base functions for all AIs.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
Definition: ai_gui.cpp:1031
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
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:213
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:1017
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:544
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:630
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:1262
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:3259
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:3319
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:814
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:759
(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:255