OpenTTD Source  1.11.2
ai_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../table/sprites.h"
12 #include "../error.h"
13 #include "../settings_gui.h"
14 #include "../querystring_gui.h"
15 #include "../stringfilter_type.h"
16 #include "../company_base.h"
17 #include "../company_gui.h"
18 #include "../strings_func.h"
19 #include "../window_func.h"
20 #include "../gfx_func.h"
21 #include "../command_func.h"
22 #include "../network/network.h"
23 #include "../settings_func.h"
24 #include "../network/network_content.h"
25 #include "../textfile_gui.h"
26 #include "../widgets/dropdown_type.h"
27 #include "../widgets/dropdown_func.h"
28 #include "../hotkeys.h"
29 #include "../core/geometry_func.hpp"
30 #include "../guitimer_func.h"
31 
32 #include "ai.hpp"
33 #include "ai_gui.hpp"
34 #include "../script/api/script_log.hpp"
35 #include "ai_config.hpp"
36 #include "ai_info.hpp"
37 #include "ai_instance.hpp"
38 #include "../game/game.hpp"
39 #include "../game/game_config.hpp"
40 #include "../game/game_info.hpp"
41 #include "../game/game_instance.hpp"
42 
43 #include "table/strings.h"
44 
45 #include <vector>
46 
47 #include "../safeguards.h"
48 
49 static ScriptConfig *GetConfig(CompanyID slot)
50 {
51  if (slot == OWNER_DEITY) return GameConfig::GetConfig();
52  return AIConfig::GetConfig(slot);
53 }
54 
58 struct AIListWindow : public Window {
60  int selected;
64 
71  slot(slot)
72  {
73  if (slot == OWNER_DEITY) {
74  this->info_list = Game::GetUniqueInfoList();
75  } else {
76  this->info_list = AI::GetUniqueInfoList();
77  }
78 
79  this->CreateNestedTree();
80  this->vscroll = this->GetScrollbar(WID_AIL_SCROLLBAR);
81  this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
82 
83  this->vscroll->SetCount((int)this->info_list->size() + 1);
84 
85  /* Try if we can find the currently selected AI */
86  this->selected = -1;
87  if (GetConfig(slot)->HasScript()) {
88  ScriptInfo *info = GetConfig(slot)->GetInfo();
89  int i = 0;
90  for (const auto &item : *this->info_list) {
91  if (item.second == info) {
92  this->selected = i;
93  break;
94  }
95 
96  i++;
97  }
98  }
99  }
100 
101  void SetStringParameters(int widget) const override
102  {
103  switch (widget) {
104  case WID_AIL_CAPTION:
105  SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
106  break;
107  }
108  }
109 
110  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
111  {
112  if (widget == WID_AIL_LIST) {
113  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
114 
115  resize->width = 1;
116  resize->height = this->line_height;
117  size->height = 5 * this->line_height;
118  }
119  }
120 
121  void DrawWidget(const Rect &r, int widget) const override
122  {
123  switch (widget) {
124  case WID_AIL_LIST: {
125  /* Draw a list of all available AIs. */
126  int y = this->GetWidget<NWidgetBase>(WID_AIL_LIST)->pos_y;
127  /* First AI in the list is hardcoded to random */
128  if (this->vscroll->IsVisible(0)) {
129  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);
130  y += this->line_height;
131  }
132  int i = 0;
133  for (const auto &item : *this->info_list) {
134  i++;
135  if (this->vscroll->IsVisible(i)) {
136  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);
137  y += this->line_height;
138  }
139  }
140  break;
141  }
142  case WID_AIL_INFO_BG: {
143  AIInfo *selected_info = nullptr;
144  int i = 0;
145  for (const auto &item : *this->info_list) {
146  i++;
147  if (this->selected == i - 1) selected_info = static_cast<AIInfo *>(item.second);
148  }
149  /* Some info about the currently selected AI. */
150  if (selected_info != nullptr) {
151  int y = r.top + WD_FRAMERECT_TOP;
152  SetDParamStr(0, selected_info->GetAuthor());
153  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_AUTHOR);
155  SetDParam(0, selected_info->GetVersion());
156  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_VERSION);
158  if (selected_info->GetURL() != nullptr) {
159  SetDParamStr(0, selected_info->GetURL());
160  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_URL);
162  }
163  SetDParamStr(0, selected_info->GetDescription());
164  DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_FRAMERECT_BOTTOM, STR_JUST_RAW_STRING, TC_WHITE);
165  }
166  break;
167  }
168  }
169  }
170 
174  void ChangeAI()
175  {
176  if (this->selected == -1) {
177  GetConfig(slot)->Change(nullptr);
178  } else {
179  ScriptInfoList::const_iterator it = this->info_list->begin();
180  for (int i = 0; i < this->selected; i++) it++;
181  GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion());
182  }
187  }
188 
189  void OnClick(Point pt, int widget, int click_count) override
190  {
191  switch (widget) {
192  case WID_AIL_LIST: { // Select one of the AIs
193  int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST, 0, this->line_height) - 1;
194  if (sel < (int)this->info_list->size()) {
195  this->selected = sel;
196  this->SetDirty();
197  if (click_count > 1) {
198  this->ChangeAI();
199  delete this;
200  }
201  }
202  break;
203  }
204 
205  case WID_AIL_ACCEPT: {
206  this->ChangeAI();
207  delete this;
208  break;
209  }
210 
211  case WID_AIL_CANCEL:
212  delete this;
213  break;
214  }
215  }
216 
217  void OnResize() override
218  {
219  this->vscroll->SetCapacityFromWidget(this, WID_AIL_LIST);
220  }
221 
227  void OnInvalidateData(int data = 0, bool gui_scope = true) override
228  {
229  if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
230  delete this;
231  return;
232  }
233 
234  if (!gui_scope) return;
235 
236  this->vscroll->SetCount((int)this->info_list->size() + 1);
237 
238  /* selected goes from -1 .. length of ai list - 1. */
239  this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
240  }
241 };
242 
246  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
247  NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
248  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
249  EndContainer(),
251  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),
252  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIL_SCROLLBAR),
253  EndContainer(),
255  EndContainer(),
258  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
259  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
260  EndContainer(),
261  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
262  EndContainer(),
263 };
264 
267  WDP_CENTER, "settings_script_list", 200, 234,
269  0,
271 );
272 
277 static void ShowAIListWindow(CompanyID slot)
278 {
280  new AIListWindow(&_ai_list_desc, slot);
281 }
282 
286 struct AISettingsWindow : public Window {
297  typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
298  VisibleSettingsList visible_settings;
299 
306  slot(slot),
307  clicked_button(-1),
308  clicked_dropdown(false),
309  closing_dropdown(false),
310  timeout(0)
311  {
312  this->ai_config = GetConfig(slot);
313 
314  this->CreateNestedTree();
315  this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
316  this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
317 
318  this->RebuildVisibleSettings();
319  }
320 
321  void SetStringParameters(int widget) const override
322  {
323  switch (widget) {
324  case WID_AIS_CAPTION:
325  SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
326  break;
327  }
328  }
329 
336  {
337  visible_settings.clear();
338 
339  for (const auto &item : *this->ai_config->GetConfigList()) {
340  bool no_hide = (item.flags & SCRIPTCONFIG_DEVELOPER) == 0;
341  if (no_hide || _settings_client.gui.ai_developer_tools) {
342  visible_settings.push_back(&item);
343  }
344  }
345 
346  this->vscroll->SetCount((int)this->visible_settings.size());
347  }
348 
349  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
350  {
351  if (widget == WID_AIS_BACKGROUND) {
352  this->line_height = std::max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
353 
354  resize->width = 1;
355  resize->height = this->line_height;
356  size->height = 5 * this->line_height;
357  }
358  }
359 
360  void DrawWidget(const Rect &r, int widget) const override
361  {
362  if (widget != WID_AIS_BACKGROUND) return;
363 
364  ScriptConfig *config = this->ai_config;
365  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
366  int i = 0;
367  for (; !this->vscroll->IsVisible(i); i++) it++;
368 
369  bool rtl = _current_text_dir == TD_RTL;
370  uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
371  uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
372  uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
373 
374 
375  int y = r.top;
376  int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
377  int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
378  for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
379  const ScriptConfigItem &config_item = **it;
380  int current_value = config->GetSetting((config_item).name);
381  bool editable = this->IsEditableItem(config_item);
382 
383  StringID str;
384  TextColour colour;
385  uint idx = 0;
386  if (StrEmpty(config_item.description)) {
387  if (!strcmp(config_item.name, "start_date")) {
388  /* Build-in translation */
389  str = STR_AI_SETTINGS_START_DELAY;
390  colour = TC_LIGHT_BLUE;
391  } else {
392  str = STR_JUST_STRING;
393  colour = TC_ORANGE;
394  }
395  } else {
396  str = STR_AI_SETTINGS_SETTING;
397  colour = TC_LIGHT_BLUE;
398  SetDParamStr(idx++, config_item.description);
399  }
400 
401  if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
402  DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
403  SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
404  } else {
405  if (config_item.complete_labels) {
406  DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
407  } else {
408  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);
409  }
410  if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
411  SetDParam(idx++, STR_JUST_RAW_STRING);
412  SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
413  } else {
414  SetDParam(idx++, STR_JUST_INT);
415  SetDParam(idx++, current_value);
416  }
417  }
418 
419  DrawString(text_left, text_right, y + text_y_offset, str, colour);
420  y += this->line_height;
421  }
422  }
423 
424  void OnPaint() override
425  {
426  if (this->closing_dropdown) {
427  this->closing_dropdown = false;
428  this->clicked_dropdown = false;
429  }
430  this->DrawWidgets();
431  }
432 
433  void OnClick(Point pt, int widget, int click_count) override
434  {
435  switch (widget) {
436  case WID_AIS_BACKGROUND: {
437  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
438  int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
439  if (num >= (int)this->visible_settings.size()) break;
440 
441  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
442  for (int i = 0; i < num; i++) it++;
443  const ScriptConfigItem config_item = **it;
444  if (!this->IsEditableItem(config_item)) return;
445 
446  if (this->clicked_row != num) {
448  HideDropDownMenu(this);
449  this->clicked_row = num;
450  this->clicked_dropdown = false;
451  }
452 
453  bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
454 
455  int x = pt.x - wid->pos_x;
456  if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x;
457  x -= 4;
458 
459  /* One of the arrows is clicked (or green/red rect in case of bool value) */
460  int old_val = this->ai_config->GetSetting(config_item.name);
461  if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
462  if (this->clicked_dropdown) {
463  /* unclick the dropdown */
464  HideDropDownMenu(this);
465  this->clicked_dropdown = false;
466  this->closing_dropdown = false;
467  } else {
468  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
469  int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
470 
471  Rect wi_rect;
472  wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
473  wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
474  wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
475  wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
476 
477  /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
478  if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
479  this->clicked_dropdown = true;
480  this->closing_dropdown = false;
481 
482  DropDownList list;
483  for (int i = config_item.min_value; i <= config_item.max_value; i++) {
484  list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
485  }
486 
487  ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
488  }
489  }
490  } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
491  int new_val = old_val;
492  if (bool_item) {
493  new_val = !new_val;
494  } else if (x >= SETTING_BUTTON_WIDTH / 2) {
495  /* Increase button clicked */
496  new_val += config_item.step_size;
497  if (new_val > config_item.max_value) new_val = config_item.max_value;
498  this->clicked_increase = true;
499  } else {
500  /* Decrease button clicked */
501  new_val -= config_item.step_size;
502  if (new_val < config_item.min_value) new_val = config_item.min_value;
503  this->clicked_increase = false;
504  }
505 
506  if (new_val != old_val) {
507  this->ai_config->SetSetting(config_item.name, new_val);
508  this->clicked_button = num;
509  this->timeout.SetInterval(150);
510  }
511  } else if (!bool_item && !config_item.complete_labels) {
512  /* Display a query box so users can enter a custom value. */
513  SetDParam(0, old_val);
514  ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
515  }
516  this->SetDirty();
517  break;
518  }
519 
520  case WID_AIS_ACCEPT:
521  delete this;
522  break;
523 
524  case WID_AIS_RESET:
525  this->ai_config->ResetEditableSettings(_game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
526  this->SetDirty();
527  break;
528  }
529  }
530 
531  void OnQueryTextFinished(char *str) override
532  {
533  if (StrEmpty(str)) return;
534  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
535  for (int i = 0; i < this->clicked_row; i++) it++;
536  const ScriptConfigItem config_item = **it;
537  if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
538  int32 value = atoi(str);
539  this->ai_config->SetSetting(config_item.name, value);
540  this->SetDirty();
541  }
542 
543  void OnDropdownSelect(int widget, int index) override
544  {
545  assert(this->clicked_dropdown);
546  VisibleSettingsList::const_iterator it = this->visible_settings.begin();
547  for (int i = 0; i < this->clicked_row; i++) it++;
548  const ScriptConfigItem config_item = **it;
549  if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
550  this->ai_config->SetSetting(config_item.name, index);
551  this->SetDirty();
552  }
553 
554  void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
555  {
556  /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
557  * the same dropdown button was clicked again, and then not open the dropdown again.
558  * So, we only remember that it was closed, and process it on the next OnPaint, which is
559  * after OnClick. */
560  assert(this->clicked_dropdown);
561  this->closing_dropdown = true;
562  this->SetDirty();
563  }
564 
565  void OnResize() override
566  {
567  this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND);
568  }
569 
570  void OnRealtimeTick(uint delta_ms) override
571  {
572  if (this->timeout.Elapsed(delta_ms)) {
573  this->clicked_button = -1;
574  this->SetDirty();
575  }
576  }
577 
583  void OnInvalidateData(int data = 0, bool gui_scope = true) override
584  {
585  this->RebuildVisibleSettings();
586  HideDropDownMenu(this);
588  }
589 
590 private:
591  bool IsEditableItem(const ScriptConfigItem &config_item) const
592  {
593  return _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
594  }
595 };
596 
600  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
601  NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
602  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
603  EndContainer(),
605  NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIS_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_AIS_SCROLLBAR),
606  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIS_SCROLLBAR),
607  EndContainer(),
610  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
611  NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
612  EndContainer(),
613  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
614  EndContainer(),
615 };
616 
619  WDP_CENTER, "settings_script", 500, 208,
621  0,
623 );
624 
630 {
634 }
635 
636 
640 
642  {
643  this->OnInvalidateData();
644  }
645 
646  void SetStringParameters(int widget) const override
647  {
648  if (widget == WID_TF_CAPTION) {
649  SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
650  SetDParamStr(1, GetConfig(slot)->GetInfo()->GetName());
651  }
652  }
653 
654  void OnInvalidateData(int data = 0, bool gui_scope = true) override
655  {
656  const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
657  if (textfile == nullptr) {
658  delete this;
659  } else {
660  this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
661  }
662  }
663 };
664 
671 {
672  DeleteWindowById(WC_TEXTFILE, file_type);
673  new ScriptTextfileWindow(file_type, slot);
674 }
675 
676 
680  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
681  NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
682  EndContainer(),
683  NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
684  NWidget(NWID_VERTICAL), SetPIP(4, 4, 4),
685  NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
686  NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE), SetFill(0, 1), SetDataTip(AWV_DECREASE, STR_NULL),
687  NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE), SetFill(0, 1), SetDataTip(AWV_INCREASE, STR_NULL),
689  NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_NUMBER), SetDataTip(STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS, STR_NULL), SetFill(1, 0), SetPadding(1, 0, 0, 0),
690  EndContainer(),
692  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),
693  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),
694  EndContainer(),
695  EndContainer(),
696  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPadding(0, 5, 0, 5),
698  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),
699  NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
700  EndContainer(),
701  EndContainer(),
703  NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetPadding(0, 5, 4, 5),
704  NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetMinimalSize(288, 14), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
705  EndContainer(),
707  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CHANGE, STR_AI_CONFIG_CHANGE_TOOLTIP),
708  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
709  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
710  EndContainer(),
712  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
713  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
714  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
715  EndContainer(),
716  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),
717  EndContainer(),
718 };
719 
722  WDP_CENTER, "settings_script_config", 0, 0,
724  0,
726 );
727 
731 struct AIConfigWindow : public Window {
735 
737  {
738  this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
739  this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
740  this->selected_slot = INVALID_COMPANY;
741  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
742  this->vscroll->SetCapacity(nwi->current_y / this->line_height);
743  this->vscroll->SetCount(MAX_COMPANIES);
744  this->OnInvalidateData(0);
745  }
746 
747  ~AIConfigWindow()
748  {
751  }
752 
753  void SetStringParameters(int widget) const override
754  {
755  switch (widget) {
756  case WID_AIC_NUMBER:
757  SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
758  break;
759  case WID_AIC_CHANGE:
760  switch (selected_slot) {
761  case OWNER_DEITY:
762  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
763  break;
764 
765  case INVALID_COMPANY:
766  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
767  break;
768 
769  default:
770  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
771  break;
772  }
773  break;
774  }
775  }
776 
777  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
778  {
779  switch (widget) {
780  case WID_AIC_GAMELIST:
781  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
782  size->height = 1 * this->line_height;
783  break;
784 
785  case WID_AIC_LIST:
786  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
787  size->height = 8 * this->line_height;
788  break;
789 
790  case WID_AIC_CHANGE: {
791  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
792  Dimension dim = GetStringBoundingBox(STR_AI_CONFIG_CHANGE);
793 
794  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
795  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
796 
797  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
798  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
799 
800  dim.width += padding.width;
801  dim.height += padding.height;
802  *size = maxdim(*size, dim);
803  break;
804  }
805  }
806  }
807 
813  static bool IsEditable(CompanyID slot)
814  {
815  if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
816 
817  if (_game_mode != GM_NORMAL) {
818  return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
819  }
820  if (Company::IsValidID(slot)) return false;
821 
823  for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
824  if (Company::IsValidHumanID(cid)) max_slot++;
825  }
826  return slot < max_slot;
827  }
828 
829  void DrawWidget(const Rect &r, int widget) const override
830  {
831  switch (widget) {
832  case WID_AIC_GAMELIST: {
833  StringID text = STR_AI_CONFIG_NONE;
834 
835  if (GameConfig::GetConfig()->GetInfo() != nullptr) {
836  SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
837  text = STR_JUST_RAW_STRING;
838  }
839 
840  DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
841  (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
842 
843  break;
844  }
845 
846  case WID_AIC_LIST: {
847  int y = r.top;
848  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
849  StringID text;
850 
851  if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
852  text = STR_AI_CONFIG_HUMAN_PLAYER;
853  } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
854  SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
855  text = STR_JUST_RAW_STRING;
856  } else {
857  text = STR_AI_CONFIG_RANDOM_AI;
858  }
859  DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
860  (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
861  y += this->line_height;
862  }
863  break;
864  }
865  }
866  }
867 
868  void OnClick(Point pt, int widget, int click_count) override
869  {
870  if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
871  if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == nullptr) return;
872 
873  ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
874  return;
875  }
876 
877  switch (widget) {
878  case WID_AIC_DECREASE:
879  case WID_AIC_INCREASE: {
880  int new_value;
881  if (widget == WID_AIC_DECREASE) {
882  new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
883  } else {
884  new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
885  }
886  IConsoleSetSetting("difficulty.max_no_competitors", new_value);
887  break;
888  }
889 
890  case WID_AIC_GAMELIST: {
891  this->selected_slot = OWNER_DEITY;
892  this->InvalidateData();
893  if (click_count > 1 && this->selected_slot != INVALID_COMPANY && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)this->selected_slot);
894  break;
895  }
896 
897  case WID_AIC_LIST: { // Select a slot
898  this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
899  this->InvalidateData();
900  if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
901  break;
902  }
903 
904  case WID_AIC_MOVE_UP:
905  if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
906  Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
907  this->selected_slot--;
908  this->vscroll->ScrollTowards(this->selected_slot);
909  this->InvalidateData();
910  }
911  break;
912 
913  case WID_AIC_MOVE_DOWN:
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_CHANGE: // choose other AI
923  ShowAIListWindow((CompanyID)this->selected_slot);
924  break;
925 
926  case WID_AIC_CONFIGURE: // change the settings for an AI
927  ShowAISettingsWindow((CompanyID)this->selected_slot);
928  break;
929 
930  case WID_AIC_CLOSE:
931  delete this;
932  break;
933 
935  if (!_network_available) {
936  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
937  } else {
939  }
940  break;
941  }
942  }
943 
949  void OnInvalidateData(int data = 0, bool gui_scope = true) override
950  {
951  if (!IsEditable(this->selected_slot)) {
952  this->selected_slot = INVALID_COMPANY;
953  }
954 
955  if (!gui_scope) return;
956 
957  this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
958  this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
959  this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
960  this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
961  this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
962  this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
963 
964  for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
965  this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == nullptr));
966  }
967  }
968 };
969 
972 {
974  new AIConfigWindow();
975 }
976 
985 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
986 {
987  /* Dead scripts are indicated with red background and
988  * paused scripts are indicated with yellow background. */
989  Colours colour = dead ? COLOUR_RED :
990  (paused ? COLOUR_YELLOW : COLOUR_GREY);
991  if (button.colour != colour) {
992  button.colour = colour;
993  return true;
994  }
995  return false;
996 }
997 
1001 struct AIDebugWindow : public Window {
1002  static const int top_offset;
1003  static const int bottom_offset;
1004 
1005  static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1006 
1010  bool autoscroll;
1012  static bool break_check_enabled;
1019 
1020  ScriptLog::LogData *GetLogPointer() const
1021  {
1022  if (ai_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
1023  return (ScriptLog::LogData *)Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1024  }
1025 
1030  bool IsDead() const
1031  {
1032  if (ai_debug_company == OWNER_DEITY) {
1033  GameInstance *game = Game::GetInstance();
1034  return game == nullptr || game->IsDead();
1035  }
1036  return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
1037  }
1038 
1044  bool IsValidDebugCompany(CompanyID company) const
1045  {
1046  switch (company) {
1047  case INVALID_COMPANY: return false;
1048  case OWNER_DEITY: return Game::GetInstance() != nullptr;
1049  default: return Company::IsValidAiID(company);
1050  }
1051  }
1052 
1058  {
1059  /* Check if the currently selected company is still active. */
1060  if (this->IsValidDebugCompany(ai_debug_company)) return;
1061 
1063 
1064  for (const Company *c : Company::Iterate()) {
1065  if (c->is_ai) {
1066  ChangeToAI(c->index);
1067  return;
1068  }
1069  }
1070 
1071  /* If no AI is available, see if there is a game script. */
1072  if (Game::GetInstance() != nullptr) ChangeToAI(OWNER_DEITY);
1073  }
1074 
1081  {
1082  this->CreateNestedTree();
1083  this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
1084  this->show_break_box = _settings_client.gui.ai_developer_tools;
1085  this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
1086  this->FinishInitNested(number);
1087 
1088  if (!this->show_break_box) break_check_enabled = false;
1089 
1090  this->last_vscroll_pos = 0;
1091  this->autoscroll = true;
1092  this->highlight_row = -1;
1093 
1095 
1097 
1098  /* Restore the break string value from static variable */
1099  this->break_editbox.text.Assign(this->break_string);
1100 
1101  this->SelectValidDebugCompany();
1102  this->InvalidateData(-1);
1103  }
1104 
1105  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1106  {
1107  if (widget == WID_AID_LOG_PANEL) {
1109  size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1110  }
1111  }
1112 
1113  void OnPaint() override
1114  {
1115  this->SelectValidDebugCompany();
1116 
1117  /* Draw standard stuff */
1118  this->DrawWidgets();
1119 
1120  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
1121 
1122  bool dirty = false;
1123 
1124  /* Paint the company icons */
1125  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1126  NWidgetCore *button = this->GetWidget<NWidgetCore>(i + WID_AID_COMPANY_BUTTON_START);
1127 
1128  bool valid = Company::IsValidAiID(i);
1129 
1130  /* Check whether the validity of the company changed */
1131  dirty |= (button->IsDisabled() == valid);
1132 
1133  /* Mark dead/paused AIs by setting the background colour. */
1134  bool dead = valid && Company::Get(i)->ai_instance->IsDead();
1135  bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
1136  /* Re-paint if the button was updated.
1137  * (note that it is intentional that SetScriptButtonColour is always called) */
1138  dirty |= SetScriptButtonColour(*button, dead, paused);
1139 
1140  /* Draw company icon only for valid AI companies */
1141  if (!valid) continue;
1142 
1143  byte offset = (i == ai_debug_company) ? 1 : 0;
1144  DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
1145  }
1146 
1147  /* Set button colour for Game Script. */
1148  GameInstance *game = Game::GetInstance();
1149  bool valid = game != nullptr;
1150  bool dead = valid && game->IsDead();
1151  bool paused = valid && game->IsPaused();
1152 
1153  NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_AID_SCRIPT_GAME);
1154  dirty |= (button->IsDisabled() == valid) || SetScriptButtonColour(*button, dead, paused);
1155 
1156  if (dirty) this->InvalidateData(-1);
1157 
1158  /* If there are no active companies, don't display anything else. */
1159  if (ai_debug_company == INVALID_COMPANY) return;
1160 
1161  ScriptLog::LogData *log = this->GetLogPointer();
1162 
1163  int scroll_count = (log == nullptr) ? 0 : log->used;
1164  if (this->vscroll->GetCount() != scroll_count) {
1165  this->vscroll->SetCount(scroll_count);
1166 
1167  /* We need a repaint */
1169  }
1170 
1171  if (log == nullptr) return;
1172 
1173  /* Detect when the user scrolls the window. Enable autoscroll when the
1174  * bottom-most line becomes visible. */
1175  if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
1176  this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
1177  }
1178  if (this->autoscroll) {
1179  int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1180  if (scroll_pos != this->vscroll->GetPosition()) {
1181  this->vscroll->SetPosition(scroll_pos);
1182 
1183  /* We need a repaint */
1186  }
1187  }
1188  this->last_vscroll_pos = this->vscroll->GetPosition();
1189  }
1190 
1191  void SetStringParameters(int widget) const override
1192  {
1193  switch (widget) {
1194  case WID_AID_NAME_TEXT:
1195  if (ai_debug_company == OWNER_DEITY) {
1196  const GameInfo *info = Game::GetInfo();
1197  assert(info != nullptr);
1198  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1199  SetDParamStr(1, info->GetName());
1200  SetDParam(2, info->GetVersion());
1202  SetDParam(0, STR_EMPTY);
1203  } else {
1204  const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
1205  assert(info != nullptr);
1206  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1207  SetDParamStr(1, info->GetName());
1208  SetDParam(2, info->GetVersion());
1209  }
1210  break;
1211  }
1212  }
1213 
1214  void DrawWidget(const Rect &r, int widget) const override
1215  {
1216  if (ai_debug_company == INVALID_COMPANY) return;
1217 
1218  switch (widget) {
1219  case WID_AID_LOG_PANEL: {
1220  ScriptLog::LogData *log = this->GetLogPointer();
1221  if (log == nullptr) return;
1222 
1223  int y = this->top_offset;
1224  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1225  int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1226  if (log->lines[pos] == nullptr) break;
1227 
1228  TextColour colour;
1229  switch (log->type[pos]) {
1230  case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
1231  case ScriptLog::LOG_SQ_ERROR: colour = TC_RED; break;
1232  case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
1233  case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
1234  case ScriptLog::LOG_ERROR: colour = TC_RED; break;
1235  default: colour = TC_BLACK; break;
1236  }
1237 
1238  /* Check if the current line should be highlighted */
1239  if (pos == this->highlight_row) {
1240  GfxFillRect(r.left + 1, r.top + y, r.right - 1, r.top + y + this->resize.step_height - WD_PAR_VSEP_NORMAL, PC_BLACK);
1241  if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
1242  }
1243 
1244  DrawString(r.left + 7, r.right - 7, r.top + y, log->lines[pos], colour, SA_LEFT | SA_FORCE);
1245  y += this->resize.step_height;
1246  }
1247  break;
1248  }
1249  }
1250  }
1251 
1256  void ChangeToAI(CompanyID show_ai)
1257  {
1258  if (!this->IsValidDebugCompany(show_ai)) return;
1259 
1260  ai_debug_company = show_ai;
1261 
1262  this->highlight_row = -1; // The highlight of one AI make little sense for another AI.
1263 
1264  /* Close AI settings window to prevent confusion */
1266 
1267  this->InvalidateData(-1);
1268 
1269  this->autoscroll = true;
1270  this->last_vscroll_pos = this->vscroll->GetPosition();
1271  }
1272 
1273  void OnClick(Point pt, int widget, int click_count) override
1274  {
1275  /* Also called for hotkeys, so check for disabledness */
1276  if (this->IsWidgetDisabled(widget)) return;
1277 
1278  /* Check which button is clicked */
1281  }
1282 
1283  switch (widget) {
1284  case WID_AID_SCRIPT_GAME:
1286  break;
1287 
1288  case WID_AID_RELOAD_TOGGLE:
1289  if (ai_debug_company == OWNER_DEITY) break;
1290  /* First kill the company of the AI, then start a new one. This should start the current AI again */
1293  break;
1294 
1295  case WID_AID_SETTINGS:
1297  break;
1298 
1300  this->break_check_enabled = !this->break_check_enabled;
1301  this->InvalidateData(-1);
1302  break;
1303 
1305  this->case_sensitive_break_check = !this->case_sensitive_break_check;
1306  this->InvalidateData(-1);
1307  break;
1308 
1309  case WID_AID_CONTINUE_BTN:
1310  /* Unpause current AI / game script and mark the corresponding script button dirty. */
1311  if (!this->IsDead()) {
1312  if (ai_debug_company == OWNER_DEITY) {
1313  Game::Unpause();
1314  } else {
1316  }
1317  }
1318 
1319  /* If the last AI/Game Script is unpaused, unpause the game too. */
1321  bool all_unpaused = !Game::IsPaused();
1322  if (all_unpaused) {
1323  for (const Company *c : Company::Iterate()) {
1324  if (c->is_ai && AI::IsPaused(c->index)) {
1325  all_unpaused = false;
1326  break;
1327  }
1328  }
1329  if (all_unpaused) {
1330  /* All scripts have been unpaused => unpause the game. */
1332  }
1333  }
1334  }
1335 
1336  this->highlight_row = -1;
1337  this->InvalidateData(-1);
1338  break;
1339  }
1340  }
1341 
1342  void OnEditboxChanged(int wid) override
1343  {
1344  if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
1345  /* Save the current string to static member so it can be restored next time the window is opened. */
1346  strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
1347  break_string_filter.SetFilterTerm(this->break_string);
1348  }
1349  }
1350 
1357  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1358  {
1359  /* If the log message is related to the active company tab, check the break string.
1360  * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1361  if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
1362  /* Get the log instance of the active company */
1363  ScriptLog::LogData *log = this->GetLogPointer();
1364 
1365  if (log != nullptr) {
1366  this->break_string_filter.ResetState();
1367  this->break_string_filter.AddLine(log->lines[log->pos]);
1368  if (this->break_string_filter.GetState()) {
1369  /* Pause execution of script. */
1370  if (!this->IsDead()) {
1371  if (ai_debug_company == OWNER_DEITY) {
1372  Game::Pause();
1373  } else {
1375  }
1376  }
1377 
1378  /* Pause the game. */
1381  }
1382 
1383  /* Highlight row that matched */
1384  this->highlight_row = log->pos;
1385  }
1386  }
1387  }
1388 
1389  if (!gui_scope) return;
1390 
1391  this->SelectValidDebugCompany();
1392 
1393  ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
1394  this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
1395 
1396  /* Update company buttons */
1397  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1400  }
1401 
1403  this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
1404 
1405  this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
1406  this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
1407 
1408  this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
1409  extern CompanyID _local_company;
1411  this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
1413  }
1414 
1415  void OnResize() override
1416  {
1417  this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
1418  }
1419 
1420  static HotkeyList hotkeys;
1421 };
1422 
1426 char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
1430 
1433 {
1434  return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, COLOUR_GREY, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
1435 }
1436 
1443 {
1444  if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1446  if (w == nullptr) return ES_NOT_HANDLED;
1447  return w->OnHotkey(hotkey);
1448 }
1449 
1450 static Hotkey aidebug_hotkeys[] = {
1451  Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
1452  Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
1453  Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
1454  Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
1455  Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
1456  Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
1457  Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
1458  Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
1459  Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
1460  Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
1461  Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
1462  Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
1463  Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
1464  Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
1465  Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
1466  Hotkey('S', "settings", WID_AID_SETTINGS),
1467  Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
1468  Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
1469  Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
1470  Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
1471  Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
1472  Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
1473  HOTKEY_LIST_END
1474 };
1475 HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
1476 
1480  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1481  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1482  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1483  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1484  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1485  EndContainer(),
1486  NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_VIEW),
1488  EndContainer(),
1490  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_SCRIPT_GAME), SetMinimalSize(100, 20), SetResize(1, 0), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
1491  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_AI_DEBUG_NAME_TOOLTIP),
1492  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1493  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1494  EndContainer(),
1497  /* Log panel */
1499  EndContainer(),
1500  /* Break string widgets */
1503  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_AID_BREAK_STR_ON_OFF_BTN), SetFill(0, 1), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
1504  NWidget(WWT_PANEL, COLOUR_GREY),
1506  NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
1507  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_AID_BREAK_STR_EDIT_BOX), SetFill(1, 1), SetResize(1, 0), SetPadding(2, 2, 2, 2), SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1508  EndContainer(),
1509  EndContainer(),
1510  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
1511  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
1512  EndContainer(),
1513  EndContainer(),
1514  EndContainer(),
1516  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AID_SCROLLBAR),
1517  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1518  EndContainer(),
1519  EndContainer(),
1520 };
1521 
1523 static WindowDesc _ai_debug_desc(
1524  WDP_AUTO, "script_debug", 600, 450,
1526  0,
1528  &AIDebugWindow::hotkeys
1529 );
1530 
1536 {
1537  if (!_networking || _network_server) {
1539  if (w == nullptr) w = new AIDebugWindow(&_ai_debug_desc, 0);
1540  if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
1541  return w;
1542  } else {
1543  ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
1544  }
1545 
1546  return nullptr;
1547 }
1548 
1553 {
1555 }
1556 
1559 {
1560  /* Network clients can't debug AIs. */
1561  if (_networking && !_network_server) return;
1562 
1563  for (const Company *c : Company::Iterate()) {
1564  if (c->is_ai && c->ai_instance->IsDead()) {
1565  ShowAIDebugWindow(c->index);
1566  break;
1567  }
1568  }
1569 
1571  if (g != nullptr && g->IsDead()) {
1573  }
1574 }
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:2878
ShowAISettingsWindow
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
Definition: ai_gui.cpp:629
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:62
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:3321
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:1002
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:367
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:1105
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1155
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:317
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
AIDebugWindow::AIDebugWindow
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
Definition: ai_gui.cpp:1080
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:293
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:77
AIDebugWindow::redraw_timer
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
Definition: ai_gui.cpp:1008
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1104
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:1432
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:110
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:244
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:1057
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:631
AISettingsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:360
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:1055
WID_AIC_NUMBER
@ WID_AIC_NUMBER
Number of AIs.
Definition: ai_widget.h:40
Window::DeleteChildWindows
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
Definition: window.cpp:1072
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:58
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
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:554
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:565
AIDebugWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:1415
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
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:78
AIDebugWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: ai_gui.cpp:1342
AIDebugGlobalHotkeys
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
Definition: ai_gui.cpp:1442
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:740
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1972
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:868
AISettingsWindow::clicked_button
int clicked_button
The button we clicked.
Definition: ai_gui.cpp:289
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:53
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:1113
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:1357
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:1832
AIDebugWindow::break_string_filter
static StringFilter break_string_filter
Log filter for break.
Definition: ai_gui.cpp:1015
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_func.h:96
ScriptTextfileWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:654
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:1273
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:1138
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:563
_nested_ai_config_widgets
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
Definition: ai_gui.cpp:678
ai_gui.hpp
ShowAIDebugWindowIfAIError
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
Definition: ai_gui.cpp:1558
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:679
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:939
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:79
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:640
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:398
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:145
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
AIListWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: ai_gui.cpp:62
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
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:1005
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
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_func.h:108
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:598
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:70
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:22
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:610
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:130
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:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:919
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1023
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:842
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:777
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:329
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:372
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:763
WID_AIS_SCROLLBAR
@ WID_AIS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: ai_widget.h:30
ai.hpp
ai_info.hpp
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
AIDebugWindow::highlight_row
int highlight_row
The output row that matches the given string, or -1.
Definition: ai_gui.cpp:1017
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:60
AIListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:121
AIDebugWindow::last_vscroll_pos
int last_vscroll_pos
Last position of the scrolling.
Definition: ai_gui.cpp:1009
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:605
AISettingsWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: ai_gui.cpp:531
WindowDesc
High level window description.
Definition: window_gui.h:166
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:813
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:438
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:116
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI developer tools
Definition: settings_type.h:176
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:2512
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:154
AISettingsWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: ai_gui.cpp:291
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:323
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition: company_type.h:66
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:622
AIDebugWindow::case_sensitive_break_check
static bool case_sensitive_break_check
Is the matching done case-sensitive.
Definition: ai_gui.cpp:1016
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
AIListWindow::AIListWindow
AIListWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
Definition: ai_gui.cpp:70
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
CMD_PAUSE
@ CMD_PAUSE
pause the game
Definition: command_type.h:256
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:1478
AISettingsWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: ai_gui.cpp:570
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:65
AIListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:63
AIListWindow::ChangeAI
void ChangeAI()
Changes the AI of the current slot.
Definition: ai_gui.cpp:174
AIDebugWindow::ai_debug_company
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
Definition: ai_gui.cpp:1007
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:59
WD_PAR_VSEP_NORMAL
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
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:63
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
AISettingsWindow::slot
CompanyID slot
The currently show company's setting.
Definition: ai_gui.cpp:287
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
AIDebugWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:1214
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:646
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:949
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:101
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:1041
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
_nested_ai_settings_widgets
static const NWidgetPart _nested_ai_settings_widgets[]
Widgets for the AI settings window.
Definition: ai_gui.cpp:598
ScriptConfig::SetSetting
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:104
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:733
_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:393
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:1141
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:133
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:433
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
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:292
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:52
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:1044
ScriptTextfileWindow
Window for displaying the textfile of a AI.
Definition: ai_gui.cpp:638
AIListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:227
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
AISettingsWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:296
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition: company_type.h:56
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:71
AISettingsWindow::AISettingsWindow
AISettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
Definition: ai_gui.cpp:305
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2484
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:114
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
AIDebugWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:1018
AIDebugWindow::show_break_box
bool show_break_box
Whether the break/debug box is visible.
Definition: ai_gui.cpp:1011
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:3261
AISettingsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: ai_gui.cpp:583
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:734
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:183
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
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:228
AIDebugWindow
Window with everything an AI prints via ScriptLog.
Definition: ai_gui.cpp:1001
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:143
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:695
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:189
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:1256
AIConfigWindow
Window to configure which AIs will start.
Definition: ai_gui.cpp:731
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1008
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:656
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
AIConfigWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:829
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:385
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:525
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:349
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:185
AISettingsWindow::visible_settings
VisibleSettingsList visible_settings
List of visible AI settings.
Definition: ai_gui.cpp:298
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:506
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
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
Scrollbar::SetPosition
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:710
WID_AIL_INFO_BG
@ WID_AIL_INFO_BG
Panel to draw some AI information on.
Definition: ai_widget.h:21
WC_AI_LIST
@ WC_AI_LIST
AI list; Window numbers:
Definition: window_type.h:277
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1123
ScriptConfig::GetSetting
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Definition: script_config.cpp:97
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:650
AIListWindow::slot
CompanyID slot
The company we're selecting a new Script for.
Definition: ai_gui.cpp:61
AISettingsWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition: ai_gui.cpp:294
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:1012
AIDebugWindow::break_string
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
Definition: ai_gui.cpp:1013
WID_AIC_LIST
@ WID_AIC_LIST
List with currently selected AIs.
Definition: ai_widget.h:42
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:3339
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:956
InitializeAIGui
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1552
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:168
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:61
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
ShowAIDebugWindow
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
Definition: ai_gui.cpp:1535
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:640
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:985
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:312
ScriptTextfileWindow::slot
CompanyID slot
View the textfile of this CompanyID slot.
Definition: ai_gui.cpp:639
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:1848
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:64
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:753
AIConfigWindow::selected_slot
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
Definition: ai_gui.cpp:732
CMD_COMPANY_CTRL
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
Definition: command_type.h:281
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
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
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:1003
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
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:360
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
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:1986
AISettingsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: ai_gui.cpp:424
AIDebugWindow::break_editbox
QueryString break_editbox
Break editbox.
Definition: ai_gui.cpp:1014
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1085
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
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:186
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:670
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:321
ScriptInstance::IsPaused
bool IsPaused()
Checks if the script is paused.
Definition: script_instance.cpp:556
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:992
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:70
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:67
Window
Data structure for an opened window.
Definition: window_gui.h:277
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:318
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:76
_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:60
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:602
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:286
AIListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: ai_gui.cpp:217
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2531
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:54
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
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:422
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:292
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:971
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:288
Company
Definition: company_base.h:110
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1262
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:1191
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:182
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:385
ScriptInstance::GetLogPointer
void * GetLogPointer()
Get the log pointer of this script.
Definition: script_instance.cpp:303
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:155
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:454
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:277
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:286
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:1010
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:581
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:974
AISettingsWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition: ai_gui.cpp:335
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:543
AISettingsWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition: ai_gui.cpp:290
AIDebugWindow::IsDead
bool IsDead() const
Check whether the currently selected AI/GS is dead.
Definition: ai_gui.cpp:1030
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:295
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79