OpenTTD Source  12.0-beta2
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) - 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  this->Close();
200  }
201  }
202  break;
203  }
204 
205  case WID_AIL_ACCEPT: {
206  this->ChangeAI();
207  this->Close();
208  break;
209  }
210 
211  case WID_AIL_CANCEL:
212  this->Close();
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  this->Close();
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  this->Close();
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  this->Close();
659  } else {
660  this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
661  }
662  }
663 };
664 
671 {
672  CloseWindowById(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  void Close() override
748  {
751  this->Window::Close();
752  }
753 
754  void SetStringParameters(int widget) const override
755  {
756  switch (widget) {
757  case WID_AIC_NUMBER:
758  SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
759  break;
760  case WID_AIC_CHANGE:
761  switch (selected_slot) {
762  case OWNER_DEITY:
763  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
764  break;
765 
766  case INVALID_COMPANY:
767  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
768  break;
769 
770  default:
771  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
772  break;
773  }
774  break;
775  }
776  }
777 
778  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
779  {
780  switch (widget) {
781  case WID_AIC_GAMELIST:
782  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
783  size->height = 1 * this->line_height;
784  break;
785 
786  case WID_AIC_LIST:
787  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
788  resize->height = this->line_height;
789  size->height = 8 * this->line_height;
790  break;
791 
792  case WID_AIC_CHANGE: {
793  SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
794  Dimension dim = GetStringBoundingBox(STR_AI_CONFIG_CHANGE);
795 
796  SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
797  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
798 
799  SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
800  dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE));
801 
802  dim.width += padding.width;
803  dim.height += padding.height;
804  *size = maxdim(*size, dim);
805  break;
806  }
807  }
808  }
809 
815  static bool IsEditable(CompanyID slot)
816  {
817  if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
818 
819  if (_game_mode != GM_NORMAL) {
820  return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
821  }
822  if (Company::IsValidID(slot)) return false;
823 
825  for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
826  if (Company::IsValidHumanID(cid)) max_slot++;
827  }
828  return slot < max_slot;
829  }
830 
831  void DrawWidget(const Rect &r, int widget) const override
832  {
833  switch (widget) {
834  case WID_AIC_GAMELIST: {
835  StringID text = STR_AI_CONFIG_NONE;
836 
837  if (GameConfig::GetConfig()->GetInfo() != nullptr) {
838  SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
839  text = STR_JUST_RAW_STRING;
840  }
841 
842  DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
843  (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
844 
845  break;
846  }
847 
848  case WID_AIC_LIST: {
849  int y = r.top;
850  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
851  StringID text;
852 
853  if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
854  text = STR_AI_CONFIG_HUMAN_PLAYER;
855  } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
856  SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
857  text = STR_JUST_RAW_STRING;
858  } else {
859  text = STR_AI_CONFIG_RANDOM_AI;
860  }
861  DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
862  (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
863  y += this->line_height;
864  }
865  break;
866  }
867  }
868  }
869 
870  void OnClick(Point pt, int widget, int click_count) override
871  {
872  if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
873  if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == nullptr) return;
874 
875  ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
876  return;
877  }
878 
879  switch (widget) {
880  case WID_AIC_DECREASE:
881  case WID_AIC_INCREASE: {
882  int new_value;
883  if (widget == WID_AIC_DECREASE) {
884  new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
885  } else {
886  new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
887  }
888  IConsoleSetSetting("difficulty.max_no_competitors", new_value);
889  break;
890  }
891 
892  case WID_AIC_GAMELIST: {
893  this->selected_slot = OWNER_DEITY;
894  this->InvalidateData();
895  if (click_count > 1 && this->selected_slot != INVALID_COMPANY && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)this->selected_slot);
896  break;
897  }
898 
899  case WID_AIC_LIST: { // Select a slot
900  this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
901  this->InvalidateData();
902  if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
903  break;
904  }
905 
906  case WID_AIC_MOVE_UP:
907  if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
908  Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
909  this->selected_slot--;
910  this->vscroll->ScrollTowards(this->selected_slot);
911  this->InvalidateData();
912  }
913  break;
914 
915  case WID_AIC_MOVE_DOWN:
916  if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
917  Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
918  this->selected_slot++;
919  this->vscroll->ScrollTowards(this->selected_slot);
920  this->InvalidateData();
921  }
922  break;
923 
924  case WID_AIC_CHANGE: // choose other AI
925  ShowAIListWindow((CompanyID)this->selected_slot);
926  break;
927 
928  case WID_AIC_CONFIGURE: // change the settings for an AI
929  ShowAISettingsWindow((CompanyID)this->selected_slot);
930  break;
931 
932  case WID_AIC_CLOSE:
933  this->Close();
934  break;
935 
937  if (!_network_available) {
938  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
939  } else {
941  }
942  break;
943  }
944  }
945 
951  void OnInvalidateData(int data = 0, bool gui_scope = true) override
952  {
953  if (!IsEditable(this->selected_slot)) {
954  this->selected_slot = INVALID_COMPANY;
955  }
956 
957  if (!gui_scope) return;
958 
959  this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
960  this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
961  this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
962  this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
963  this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
964  this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
965 
966  for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
967  this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == nullptr));
968  }
969  }
970 };
971 
974 {
976  new AIConfigWindow();
977 }
978 
987 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
988 {
989  /* Dead scripts are indicated with red background and
990  * paused scripts are indicated with yellow background. */
991  Colours colour = dead ? COLOUR_RED :
992  (paused ? COLOUR_YELLOW : COLOUR_GREY);
993  if (button.colour != colour) {
994  button.colour = colour;
995  return true;
996  }
997  return false;
998 }
999 
1003 struct AIDebugWindow : public Window {
1004  static const int top_offset;
1005  static const int bottom_offset;
1006 
1007  static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1008 
1012  bool autoscroll;
1014  static bool break_check_enabled;
1021 
1022  ScriptLog::LogData *GetLogPointer() const
1023  {
1024  if (ai_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
1025  return (ScriptLog::LogData *)Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1026  }
1027 
1032  bool IsDead() const
1033  {
1034  if (ai_debug_company == OWNER_DEITY) {
1035  GameInstance *game = Game::GetInstance();
1036  return game == nullptr || game->IsDead();
1037  }
1038  return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
1039  }
1040 
1046  bool IsValidDebugCompany(CompanyID company) const
1047  {
1048  switch (company) {
1049  case INVALID_COMPANY: return false;
1050  case OWNER_DEITY: return Game::GetInstance() != nullptr;
1051  default: return Company::IsValidAiID(company);
1052  }
1053  }
1054 
1060  {
1061  /* Check if the currently selected company is still active. */
1062  if (this->IsValidDebugCompany(ai_debug_company)) return;
1063 
1065 
1066  for (const Company *c : Company::Iterate()) {
1067  if (c->is_ai) {
1068  ChangeToAI(c->index);
1069  return;
1070  }
1071  }
1072 
1073  /* If no AI is available, see if there is a game script. */
1074  if (Game::GetInstance() != nullptr) ChangeToAI(OWNER_DEITY);
1075  }
1076 
1083  {
1084  this->CreateNestedTree();
1085  this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
1086  this->show_break_box = _settings_client.gui.ai_developer_tools;
1087  this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
1088  this->FinishInitNested(number);
1089 
1090  if (!this->show_break_box) break_check_enabled = false;
1091 
1092  this->last_vscroll_pos = 0;
1093  this->autoscroll = true;
1094  this->highlight_row = -1;
1095 
1097 
1099 
1100  /* Restore the break string value from static variable */
1101  this->break_editbox.text.Assign(this->break_string);
1102 
1103  this->SelectValidDebugCompany();
1104  this->InvalidateData(-1);
1105  }
1106 
1107  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1108  {
1109  if (widget == WID_AID_LOG_PANEL) {
1111  size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1112  }
1113  }
1114 
1115  void OnPaint() override
1116  {
1117  this->SelectValidDebugCompany();
1118 
1119  /* Draw standard stuff */
1120  this->DrawWidgets();
1121 
1122  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
1123 
1124  bool dirty = false;
1125 
1126  /* Paint the company icons */
1127  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1128  NWidgetCore *button = this->GetWidget<NWidgetCore>(i + WID_AID_COMPANY_BUTTON_START);
1129 
1130  bool valid = Company::IsValidAiID(i);
1131 
1132  /* Check whether the validity of the company changed */
1133  dirty |= (button->IsDisabled() == valid);
1134 
1135  /* Mark dead/paused AIs by setting the background colour. */
1136  bool dead = valid && Company::Get(i)->ai_instance->IsDead();
1137  bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
1138  /* Re-paint if the button was updated.
1139  * (note that it is intentional that SetScriptButtonColour is always called) */
1140  dirty |= SetScriptButtonColour(*button, dead, paused);
1141 
1142  /* Draw company icon only for valid AI companies */
1143  if (!valid) continue;
1144 
1145  byte offset = (i == ai_debug_company) ? 1 : 0;
1146  DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
1147  }
1148 
1149  /* Set button colour for Game Script. */
1150  GameInstance *game = Game::GetInstance();
1151  bool valid = game != nullptr;
1152  bool dead = valid && game->IsDead();
1153  bool paused = valid && game->IsPaused();
1154 
1155  NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_AID_SCRIPT_GAME);
1156  dirty |= (button->IsDisabled() == valid) || SetScriptButtonColour(*button, dead, paused);
1157 
1158  if (dirty) this->InvalidateData(-1);
1159 
1160  /* If there are no active companies, don't display anything else. */
1161  if (ai_debug_company == INVALID_COMPANY) return;
1162 
1163  ScriptLog::LogData *log = this->GetLogPointer();
1164 
1165  int scroll_count = (log == nullptr) ? 0 : log->used;
1166  if (this->vscroll->GetCount() != scroll_count) {
1167  this->vscroll->SetCount(scroll_count);
1168 
1169  /* We need a repaint */
1171  }
1172 
1173  if (log == nullptr) return;
1174 
1175  /* Detect when the user scrolls the window. Enable autoscroll when the
1176  * bottom-most line becomes visible. */
1177  if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
1178  this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
1179  }
1180  if (this->autoscroll) {
1181  int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1182  if (scroll_pos != this->vscroll->GetPosition()) {
1183  this->vscroll->SetPosition(scroll_pos);
1184 
1185  /* We need a repaint */
1188  }
1189  }
1190  this->last_vscroll_pos = this->vscroll->GetPosition();
1191  }
1192 
1193  void SetStringParameters(int widget) const override
1194  {
1195  switch (widget) {
1196  case WID_AID_NAME_TEXT:
1197  if (ai_debug_company == OWNER_DEITY) {
1198  const GameInfo *info = Game::GetInfo();
1199  assert(info != nullptr);
1200  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1201  SetDParamStr(1, info->GetName());
1202  SetDParam(2, info->GetVersion());
1204  SetDParam(0, STR_EMPTY);
1205  } else {
1206  const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
1207  assert(info != nullptr);
1208  SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1209  SetDParamStr(1, info->GetName());
1210  SetDParam(2, info->GetVersion());
1211  }
1212  break;
1213  }
1214  }
1215 
1216  void DrawWidget(const Rect &r, int widget) const override
1217  {
1218  if (ai_debug_company == INVALID_COMPANY) return;
1219 
1220  switch (widget) {
1221  case WID_AID_LOG_PANEL: {
1222  ScriptLog::LogData *log = this->GetLogPointer();
1223  if (log == nullptr) return;
1224 
1225  int y = this->top_offset;
1226  for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1227  int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1228  if (log->lines[pos] == nullptr) break;
1229 
1230  TextColour colour;
1231  switch (log->type[pos]) {
1232  case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
1233  case ScriptLog::LOG_SQ_ERROR: colour = TC_RED; break;
1234  case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
1235  case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
1236  case ScriptLog::LOG_ERROR: colour = TC_RED; break;
1237  default: colour = TC_BLACK; break;
1238  }
1239 
1240  /* Check if the current line should be highlighted */
1241  if (pos == this->highlight_row) {
1242  GfxFillRect(r.left + 1, r.top + y, r.right - 1, r.top + y + this->resize.step_height - WD_PAR_VSEP_NORMAL, PC_BLACK);
1243  if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
1244  }
1245 
1246  DrawString(r.left + 7, r.right - 7, r.top + y, log->lines[pos], colour, SA_LEFT | SA_FORCE);
1247  y += this->resize.step_height;
1248  }
1249  break;
1250  }
1251  }
1252  }
1253 
1258  void ChangeToAI(CompanyID show_ai)
1259  {
1260  if (!this->IsValidDebugCompany(show_ai)) return;
1261 
1262  ai_debug_company = show_ai;
1263 
1264  this->highlight_row = -1; // The highlight of one AI make little sense for another AI.
1265 
1266  /* Close AI settings window to prevent confusion */
1268 
1269  this->InvalidateData(-1);
1270 
1271  this->autoscroll = true;
1272  this->last_vscroll_pos = this->vscroll->GetPosition();
1273  }
1274 
1275  void OnClick(Point pt, int widget, int click_count) override
1276  {
1277  /* Also called for hotkeys, so check for disabledness */
1278  if (this->IsWidgetDisabled(widget)) return;
1279 
1280  /* Check which button is clicked */
1283  }
1284 
1285  switch (widget) {
1286  case WID_AID_SCRIPT_GAME:
1288  break;
1289 
1290  case WID_AID_RELOAD_TOGGLE:
1291  if (ai_debug_company == OWNER_DEITY) break;
1292  /* First kill the company of the AI, then start a new one. This should start the current AI again */
1295  break;
1296 
1297  case WID_AID_SETTINGS:
1299  break;
1300 
1302  this->break_check_enabled = !this->break_check_enabled;
1303  this->InvalidateData(-1);
1304  break;
1305 
1307  this->case_sensitive_break_check = !this->case_sensitive_break_check;
1308  this->InvalidateData(-1);
1309  break;
1310 
1311  case WID_AID_CONTINUE_BTN:
1312  /* Unpause current AI / game script and mark the corresponding script button dirty. */
1313  if (!this->IsDead()) {
1314  if (ai_debug_company == OWNER_DEITY) {
1315  Game::Unpause();
1316  } else {
1318  }
1319  }
1320 
1321  /* If the last AI/Game Script is unpaused, unpause the game too. */
1323  bool all_unpaused = !Game::IsPaused();
1324  if (all_unpaused) {
1325  for (const Company *c : Company::Iterate()) {
1326  if (c->is_ai && AI::IsPaused(c->index)) {
1327  all_unpaused = false;
1328  break;
1329  }
1330  }
1331  if (all_unpaused) {
1332  /* All scripts have been unpaused => unpause the game. */
1334  }
1335  }
1336  }
1337 
1338  this->highlight_row = -1;
1339  this->InvalidateData(-1);
1340  break;
1341  }
1342  }
1343 
1344  void OnEditboxChanged(int wid) override
1345  {
1346  if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
1347  /* Save the current string to static member so it can be restored next time the window is opened. */
1348  strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
1349  break_string_filter.SetFilterTerm(this->break_string);
1350  }
1351  }
1352 
1359  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1360  {
1361  /* If the log message is related to the active company tab, check the break string.
1362  * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1363  if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
1364  /* Get the log instance of the active company */
1365  ScriptLog::LogData *log = this->GetLogPointer();
1366 
1367  if (log != nullptr) {
1368  this->break_string_filter.ResetState();
1369  this->break_string_filter.AddLine(log->lines[log->pos]);
1370  if (this->break_string_filter.GetState()) {
1371  /* Pause execution of script. */
1372  if (!this->IsDead()) {
1373  if (ai_debug_company == OWNER_DEITY) {
1374  Game::Pause();
1375  } else {
1377  }
1378  }
1379 
1380  /* Pause the game. */
1383  }
1384 
1385  /* Highlight row that matched */
1386  this->highlight_row = log->pos;
1387  }
1388  }
1389  }
1390 
1391  if (!gui_scope) return;
1392 
1393  this->SelectValidDebugCompany();
1394 
1395  ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
1396  this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
1397 
1398  /* Update company buttons */
1399  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1402  }
1403 
1405  this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
1406 
1407  this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
1408  this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
1409 
1410  this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
1411  extern CompanyID _local_company;
1413  this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
1415  }
1416 
1417  void OnResize() override
1418  {
1419  this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
1420  }
1421 
1422  static HotkeyList hotkeys;
1423 };
1424 
1428 char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
1432 
1435 {
1436  return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, COLOUR_GREY, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
1437 }
1438 
1445 {
1446  if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1448  if (w == nullptr) return ES_NOT_HANDLED;
1449  return w->OnHotkey(hotkey);
1450 }
1451 
1452 static Hotkey aidebug_hotkeys[] = {
1453  Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
1454  Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
1455  Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
1456  Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
1457  Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
1458  Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
1459  Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
1460  Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
1461  Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
1462  Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
1463  Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
1464  Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
1465  Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
1466  Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
1467  Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
1468  Hotkey('S', "settings", WID_AID_SETTINGS),
1469  Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
1470  Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
1471  Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
1472  Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
1473  Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
1474  Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
1475  HOTKEY_LIST_END
1476 };
1477 HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
1478 
1482  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1483  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1484  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1485  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1486  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1487  EndContainer(),
1488  NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_VIEW),
1490  EndContainer(),
1492  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),
1493  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_AI_DEBUG_NAME_TOOLTIP),
1494  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1495  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1496  EndContainer(),
1499  /* Log panel */
1501  EndContainer(),
1502  /* Break string widgets */
1505  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),
1506  NWidget(WWT_PANEL, COLOUR_GREY),
1508  NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
1509  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),
1510  EndContainer(),
1511  EndContainer(),
1512  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),
1513  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),
1514  EndContainer(),
1515  EndContainer(),
1516  EndContainer(),
1518  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AID_SCROLLBAR),
1519  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1520  EndContainer(),
1521  EndContainer(),
1522 };
1523 
1525 static WindowDesc _ai_debug_desc(
1526  WDP_AUTO, "script_debug", 600, 450,
1528  0,
1530  &AIDebugWindow::hotkeys
1531 );
1532 
1538 {
1539  if (!_networking || _network_server) {
1541  if (w == nullptr) w = new AIDebugWindow(&_ai_debug_desc, 0);
1542  if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
1543  return w;
1544  } else {
1545  ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
1546  }
1547 
1548  return nullptr;
1549 }
1550 
1555 {
1557 }
1558 
1561 {
1562  /* Network clients can't debug AIs. */
1563  if (_networking && !_network_server) return;
1564 
1565  for (const Company *c : Company::Iterate()) {
1566  if (c->is_ai && c->ai_instance->IsDead()) {
1567  ShowAIDebugWindow(c->index);
1568  break;
1569  }
1570  }
1571 
1573  if (g != nullptr && g->IsDead()) {
1575  }
1576 }
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:3088
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:64
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3218
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:1004
Game::IsPaused
static bool IsPaused()
Checks if the Game Script is paused.
Definition: game_core.cpp:136
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:390
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
AIDebugWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp:1107
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1239
Game::GetGameInstance
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
Definition: game.hpp:75
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:340
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
AIDebugWindow::AIDebugWindow
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
Definition: ai_gui.cpp:1082
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:79
AIDebugWindow::redraw_timer
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
Definition: ai_gui.cpp:1010
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
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:1434
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:1059
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:662
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:1139
WID_AIC_NUMBER
@ WID_AIC_NUMBER
Number of AIs.
Definition: ai_widget.h:40
WID_AID_BREAK_STR_ON_OFF_BTN
@ WID_AID_BREAK_STR_ON_OFF_BTN
Enable breaking on string.
Definition: ai_widget.h:65
AIListWindow
Window that let you choose an available AI.
Definition: ai_gui.cpp:58
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WID_AIC_DECREASE
@ WID_AIC_DECREASE
Decrease the number of AIs.
Definition: ai_widget.h:38
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:42
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
AISettingsWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: ai_gui.cpp: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:1417
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:80
AIDebugWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: ai_gui.cpp:1344
AIDebugGlobalHotkeys
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
Definition: ai_gui.cpp:1444
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:775
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
AIConfigWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: ai_gui.cpp:870
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:57
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:1115
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:1359
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
AIDebugWindow::break_string_filter
static StringFilter break_string_filter
Log filter for break.
Definition: ai_gui.cpp:1017
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:1275
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:1113
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:575
_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:1560
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:710
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:993
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:52
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:642
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:422
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:147
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:106
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
AIDebugWindow::MAX_BREAK_STR_STRING_LENGTH
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
Definition: ai_gui.cpp:1007
WID_AID_SETTINGS
@ WID_AID_SETTINGS
Settings button.
Definition: ai_widget.h:57
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
Game::Unpause
static void Unpause()
Resume execution of the Game Script.
Definition: game_core.cpp:131
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2098
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:629
WID_AID_MATCH_CASE_BTN
@ WID_AID_MATCH_CASE_BTN
Checkbox to use match caching or not.
Definition: ai_widget.h:67
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
WID_AIC_MOVE_UP
@ WID_AIC_MOVE_UP
Move up button.
Definition: ai_widget.h:44
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:30
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF changelog.
Definition: textfile_type.h:18
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:621
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:133
ScriptInfo::GetDescription
const char * GetDescription() const
Get the description of the script.
Definition: script_info.hpp:65
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
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:888
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:778
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:383
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:787
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:1019
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
AIListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:121
AIDebugWindow::last_vscroll_pos
int last_vscroll_pos
Last position of the scrolling.
Definition: ai_gui.cpp:1011
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:617
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:168
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:45
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition: ai_core.cpp:133
AIConfigWindow::IsEditable
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Definition: ai_gui.cpp:815
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:463
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content_type.h:26
WID_AIL_CANCEL
@ WID_AIL_CANCEL
Cancel button.
Definition: ai_widget.h:23
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:115
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI developer tools
Definition: settings_type.h:187
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:2529
WID_AID_LOG_PANEL
@ WID_AID_LOG_PANEL
Panel where the log is in.
Definition: ai_widget.h:60
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
AISettingsWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: ai_gui.cpp: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:317
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:653
AIDebugWindow::case_sensitive_break_check
static bool case_sensitive_break_check
Is the matching done case-sensitive.
Definition: ai_gui.cpp:1018
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:1789
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:1480
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:993
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:68
AIConfigWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: ai_gui.cpp:747
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:1009
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:139
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WID_AID_SCROLLBAR
@ WID_AID_SCROLLBAR
Scrollbar of the log panel.
Definition: ai_widget.h:61
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
AISettingsWindow::slot
CompanyID slot
The currently show company's setting.
Definition: ai_gui.cpp:287
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
AIDebugWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:1216
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:951
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:1125
_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:107
WID_AID_COMPANY_BUTTON_END
@ WID_AID_COMPANY_BUTTON_END
Last possible button in the VIEW.
Definition: ai_widget.h:63
AIConfigWindow::line_height
int line_height
Height of a single AI-name line.
Definition: ai_gui.cpp:733
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:340
_ai_config_desc
static WindowDesc _ai_config_desc(WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
Window definition for the configure AI window.
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:25
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:26
WID_AIS_BACKGROUND
@ WID_AIS_BACKGROUND
Panel to draw the settings on.
Definition: ai_widget.h:29
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1118
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:135
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:64
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:56
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:1046
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:73
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:190
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2501
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:116
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
AIDebugWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition: ai_gui.cpp:1020
AIDebugWindow::show_break_box
bool show_break_box
Whether the break/debug box is visible.
Definition: ai_gui.cpp:1013
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:3158
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:187
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
ScriptConfig::GetTextfile
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:235
AIDebugWindow
Window with everything an AI prints via ScriptLog.
Definition: ai_gui.cpp:1003
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:726
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:1258
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:604
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
WID_AIC_CLOSE
@ WID_AIC_CLOSE
Close window button.
Definition: ai_widget.h:48
WC_AI_DEBUG
@ WC_AI_DEBUG
AI debug window; Window numbers:
Definition: window_type.h:654
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
AIConfigWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: ai_gui.cpp:831
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:416
WID_AID_BREAK_STR_EDIT_BOX
@ WID_AID_BREAK_STR_EDIT_BOX
Edit box for the string to break on.
Definition: ai_widget.h:66
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
AISettingsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: ai_gui.cpp: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:189
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:498
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
ScriptConfigItem::description
const char * description
The description of the configuration setting.
Definition: script_config.hpp:34
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1080
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
WID_AIL_INFO_BG
@ WID_AIL_INFO_BG
Panel to draw some AI information on.
Definition: ai_widget.h:21
WC_AI_LIST
@ WC_AI_LIST
AI list; Window numbers:
Definition: window_type.h:276
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:165
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
ScriptConfig::GetSetting
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Definition: script_config.cpp:100
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:681
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:1014
AIDebugWindow::break_string
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
Definition: ai_gui.cpp:1015
WID_AIC_LIST
@ WID_AIC_LIST
List with currently selected AIs.
Definition: ai_widget.h:42
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3235
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
InitializeAIGui
void InitializeAIGui()
Reset the AI windows to their initial state.
Definition: ai_gui.cpp:1554
WID_AID_BREAK_STRING_WIDGETS
@ WID_AID_BREAK_STRING_WIDGETS
The panel to handle the breaking on string.
Definition: ai_widget.h:64
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
WC_AI_SETTINGS
@ WC_AI_SETTINGS
AI settings; Window numbers:
Definition: window_type.h:167
ScriptConfig
Script settings.
Definition: script_config.hpp:55
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:62
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:547
ShowAIDebugWindow
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
Definition: ai_gui.cpp:1537
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:671
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:987
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:333
ScriptTextfileWindow::slot
CompanyID slot
View the textfile of this CompanyID slot.
Definition: ai_gui.cpp: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:1776
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
DifficultySettings::max_no_competitors
byte max_no_competitors
the number of competitors (AIs)
Definition: settings_type.h:74
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:754
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
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
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:1005
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:356
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
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:2172
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:1016
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1169
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
WID_AIC_INCREASE
@ WID_AIC_INCREASE
Increase the number of AIs.
Definition: ai_widget.h:39
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:43
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition: ai_core.cpp:333
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
Definition: ai_gui.cpp: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:557
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:1076
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:73
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:67
Window
Data structure for an opened window.
Definition: window_gui.h:279
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:78
_ai_debug_desc
static WindowDesc _ai_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_AI_DEBUG, WC_NONE, 0, _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets), &AIDebugWindow::hotkeys)
Window definition for the AI debug window.
AIListWindow::selected
int selected
The currently selected Script.
Definition: ai_gui.cpp: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:636
ScriptInfo::GetName
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:55
AISettingsWindow
Window for settings the parameters of an AI.
Definition: ai_gui.cpp: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:2548
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:58
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:415
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
ShowAIConfigWindow
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:973
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:115
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1259
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:32
AIDebugWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: ai_gui.cpp:1193
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
WID_AIL_CAPTION
@ WID_AIL_CAPTION
Caption of the window.
Definition: ai_widget.h:18
ScriptConfigItem::name
const char * name
The name of the configuration setting.
Definition: script_config.hpp:33
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:179
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
ScriptInstance::GetLogPointer
void * GetLogPointer()
Get the log pointer of this script.
Definition: script_instance.cpp:305
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
ShowAIListWindow
static void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
Definition: ai_gui.cpp: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:296
WID_AIC_BACKGROUND
@ WID_AIC_BACKGROUND
Window background.
Definition: ai_widget.h:37
AIDebugWindow::autoscroll
bool autoscroll
Whether automatically scrolling should be enabled or not.
Definition: ai_gui.cpp:1012
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:593
Scrollbar::SetPosition
bool SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:742
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:1028
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:1032
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
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79