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