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