10 #include "../stdafx.h" 11 #include "../table/sprites.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" 34 #include "../script/api/script_log.hpp" 38 #include "../game/game.hpp" 39 #include "../game/game_config.hpp" 40 #include "../game/game_info.hpp" 41 #include "../game/game_instance.hpp" 43 #include "table/strings.h" 47 #include "../safeguards.h" 83 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
90 for (ScriptInfoList::const_iterator it = this->info_list->begin(); it != this->info_list->end(); it++, i++) {
91 if ((*it).second == info) {
103 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
124 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
130 ScriptInfoList::const_iterator it = this->info_list->begin();
131 for (
int i = 1; it != this->info_list->end(); i++, it++) {
140 AIInfo *selected_info =
nullptr;
141 ScriptInfoList::const_iterator it = this->info_list->begin();
142 for (
int i = 1; selected_info ==
nullptr && it != this->info_list->end(); i++, it++) {
143 if (this->selected == i - 1) selected_info =
static_cast<AIInfo *
>((*it).second);
146 if (selected_info !=
nullptr) {
154 if (selected_info->
GetURL() !=
nullptr) {
172 if (this->selected == -1) {
173 GetConfig(slot)->
Change(
nullptr);
175 ScriptInfoList::const_iterator it = this->info_list->begin();
176 for (
int i = 0; i < this->
selected; i++) it++;
177 GetConfig(slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
190 if (sel < (
int)this->info_list->size()) {
191 this->selected = sel;
193 if (click_count > 1) {
230 if (!gui_scope)
return;
232 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
235 this->selected =
min(this->selected, this->vscroll->
GetCount() - 2);
247 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIL_LIST),
SetMinimalSize(188, 112),
SetFill(1, 1),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP),
SetScrollbar(
WID_AIL_SCROLLBAR),
266 _nested_ai_list_widgets,
lengthof(_nested_ai_list_widgets)
293 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
304 clicked_dropdown(false),
305 closing_dropdown(false),
308 this->ai_config = GetConfig(slot);
316 this->RebuildVisibleSettings();
323 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
335 visible_settings.clear();
337 ScriptConfigItemList::const_iterator it = this->ai_config->
GetConfigList()->begin();
338 for (; it != this->ai_config->
GetConfigList()->end(); it++) {
341 visible_settings.push_back(&(*it));
345 this->vscroll->
SetCount((
int)this->visible_settings.size());
364 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
366 for (; !this->vscroll->
IsVisible(i); i++) it++;
377 for (; this->vscroll->
IsVisible(i) && it != visible_settings.end(); i++, it++) {
379 int current_value = config->
GetSetting((config_item).name);
380 bool editable = this->IsEditableItem(config_item);
386 if (!strcmp(config_item.
name,
"start_date")) {
388 str = STR_AI_SETTINGS_START_DELAY;
389 colour = TC_LIGHT_BLUE;
391 str = STR_JUST_STRING;
395 str = STR_AI_SETTINGS_SETTING;
396 colour = TC_LIGHT_BLUE;
401 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
402 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
405 DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
407 DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.
min_value, editable && current_value < config_item.
max_value);
418 DrawString(text_left, text_right, y + text_y_offset, str, colour);
425 if (this->closing_dropdown) {
426 this->closing_dropdown =
false;
427 this->clicked_dropdown =
false;
437 int num = (pt.y - wid->
pos_y) / this->line_height + this->vscroll->
GetPosition();
438 if (num >= (
int)this->visible_settings.size())
break;
440 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
441 for (
int i = 0; i < num; i++) it++;
443 if (!this->IsEditableItem(config_item))
return;
445 if (this->clicked_row != num) {
448 this->clicked_row = num;
449 this->clicked_dropdown =
false;
454 int x = pt.x - wid->
pos_x;
461 if (this->clicked_dropdown) {
464 this->clicked_dropdown =
false;
465 this->closing_dropdown =
false;
477 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
478 this->clicked_dropdown =
true;
479 this->closing_dropdown =
false;
490 int new_val = old_val;
497 this->clicked_increase =
true;
502 this->clicked_increase =
false;
505 if (new_val != old_val) {
507 this->clicked_button = num;
508 this->timeout.SetInterval(150);
535 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
536 for (
int i = 0; i < this->clicked_row; i++) it++;
539 int32 value = atoi(str);
546 assert(this->clicked_dropdown);
547 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
548 for (
int i = 0; i < this->clicked_row; i++) it++;
561 assert(this->clicked_dropdown);
562 this->closing_dropdown =
true;
573 if (this->timeout.
Elapsed(delta_ms)) {
574 this->clicked_button = -1;
586 this->RebuildVisibleSettings();
606 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_AIS_SCROLLBAR),
623 _nested_ai_settings_widgets,
lengthof(_nested_ai_settings_widgets)
657 const char *textfile = GetConfig(slot)->
GetTextfile(file_type, slot);
658 if (textfile ==
nullptr) {
690 NWidget(
WWT_TEXT, COLOUR_MAUVE,
WID_AIC_NUMBER),
SetDataTip(STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS, STR_NULL),
SetFill(1, 0),
SetPadding(1, 0, 0, 0),
699 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_LIST),
SetMinimalSize(288, 112),
SetFill(1, 0),
SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP),
SetScrollbar(
WID_AIC_SCROLLBAR),
705 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
717 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_AIC_CONTENT_DOWNLOAD),
SetFill(1, 0),
SetMinimalSize(279, 12),
SetPadding(0, 7, 9, 7),
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
726 _nested_ai_config_widgets,
lengthof(_nested_ai_config_widgets)
761 switch (selected_slot) {
763 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
792 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
801 dim.width += padding.width;
802 dim.height += padding.height;
803 *size =
maxdim(*size, dim);
818 if (_game_mode != GM_NORMAL) {
827 return slot < max_slot;
838 text = STR_JUST_RAW_STRING;
853 text = STR_AI_CONFIG_HUMAN_PLAYER;
856 text = STR_JUST_RAW_STRING;
858 text = STR_AI_CONFIG_RANDOM_AI;
861 (this->selected_slot == i) ? TC_WHITE : (IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
872 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) ==
nullptr)
return;
887 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
906 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot - 1))) {
908 this->selected_slot--;
915 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot + 1))) {
917 this->selected_slot++;
952 if (!IsEditable(this->selected_slot)) {
956 if (!gui_scope)
return;
965 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
990 Colours colour = dead ? COLOUR_RED :
991 (paused ? COLOUR_YELLOW : COLOUR_GREY);
992 if (button.
colour != colour) {
1006 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1014 static char break_string[MAX_BREAK_STR_STRING_LENGTH];
1021 ScriptLog::LogData *GetLogPointer()
const 1024 return (ScriptLog::LogData *)
Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1035 return game ==
nullptr || game->
IsDead();
1061 if (this->IsValidDebugCompany(ai_debug_company))
return;
1067 ChangeToAI(c->index);
1089 if (!this->show_break_box) break_check_enabled =
false;
1091 this->last_vscroll_pos = 0;
1092 this->autoscroll =
true;
1093 this->highlight_row = -1;
1100 this->break_editbox.text.
Assign(this->break_string);
1102 this->SelectValidDebugCompany();
1110 size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1116 this->SelectValidDebugCompany();
1135 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
1136 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
1142 if (!valid)
continue;
1144 byte offset = (i == ai_debug_company) ? 1 : 0;
1150 bool valid = game !=
nullptr;
1151 bool dead = valid && game->
IsDead();
1152 bool paused = valid && game->
IsPaused();
1162 ScriptLog::LogData *log = this->GetLogPointer();
1164 int scroll_count = (log ==
nullptr) ? 0 : log->used;
1165 if (this->vscroll->
GetCount() != scroll_count) {
1166 this->vscroll->
SetCount(scroll_count);
1172 if (log ==
nullptr)
return;
1176 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1179 if (this->autoscroll) {
1180 int scroll_pos =
max(0, log->used - this->vscroll->GetCapacity());
1189 this->last_vscroll_pos = this->vscroll->
GetPosition();
1198 assert(info !=
nullptr);
1199 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1206 assert(info !=
nullptr);
1207 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1221 ScriptLog::LogData *log = this->GetLogPointer();
1222 if (log ==
nullptr)
return;
1224 int y = this->top_offset;
1225 for (
int i = this->vscroll->
GetPosition(); this->vscroll->
IsVisible(i) && i < log->used; i++) {
1226 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1227 if (log->lines[pos] ==
nullptr)
break;
1230 switch (log->type[pos]) {
1231 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1232 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1233 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1234 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1235 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1236 default: colour = TC_BLACK;
break;
1240 if (pos == this->highlight_row) {
1242 if (colour == TC_BLACK) colour = TC_WHITE;
1259 if (!this->IsValidDebugCompany(show_ai))
return;
1261 ai_debug_company = show_ai;
1263 this->highlight_row = -1;
1270 this->autoscroll =
true;
1271 this->last_vscroll_pos = this->vscroll->
GetPosition();
1301 this->break_check_enabled = !this->break_check_enabled;
1306 this->case_sensitive_break_check = !this->case_sensitive_break_check;
1312 if (!this->IsDead()) {
1326 all_unpaused =
false;
1337 this->highlight_row = -1;
1347 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1362 if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.
IsEmpty()) {
1364 ScriptLog::LogData *log = this->GetLogPointer();
1366 if (log !=
nullptr) {
1368 this->break_string_filter.
AddLine(log->lines[log->pos]);
1369 if (this->break_string_filter.
GetState()) {
1371 if (!this->IsDead()) {
1385 this->highlight_row = log->pos;
1390 if (!gui_scope)
return;
1392 this->SelectValidDebugCompany();
1394 ScriptLog::LogData *log = ai_debug_company !=
INVALID_COMPANY ? this->GetLogPointer() :
nullptr;
1395 this->vscroll->
SetCount((log ==
nullptr) ? 0 : log->used);
1450 static Hotkey aidebug_hotkeys[] = {
1507 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_AID_BREAK_STR_EDIT_BOX),
SetFill(1, 1),
SetResize(1, 0),
SetPadding(2, 2, 2, 2),
SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1524 WDP_AUTO,
"script_debug", 600, 450,
1527 _nested_ai_debug_widgets,
lengthof(_nested_ai_debug_widgets),
1528 &AIDebugWindow::hotkeys
1539 if (w ==
nullptr) w =
new AIDebugWindow(&_ai_debug_desc, 0);
1564 if (c->is_ai && c->ai_instance->IsDead()) {
1571 if (g !=
nullptr && g->
IsDead()) {
EventState
State of handling an event.
GUITimer timeout
Timeout for unclicking the button.
Owner
Enum for all companies/owners.
static void Swap(T &a, T &b)
Type safe swap operation.
int GetVersion() const
Get the version of the script.
used in multiplayer to create a new companies etc.
This setting will only be visible when the Script development tools are active.
bool _networking
are we in networking mode?
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool autoscroll
Whether automatically scrolling should be enabled or not.
ResizeInfo resize
Resize information.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Scrollbar * vscroll
Cache of the vertical scrollbar.
ScriptConfig * ai_config
The configuration we're modifying.
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...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Offset at right of a matrix cell.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
static bool break_check_enabled
Stop an AI when it prints a matching string.
static void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
All data for a single hotkey.
High level window description.
static void Unpause(CompanyID company)
Resume execution of the AI.
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.
void DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
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.
Offset at top to draw the frame rectangular area.
Scrollbar * vscroll
Cache of the vertical scrollbar.
Normal amount of vertical space between two paragraphs of text.
textfile; Window numbers:
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool Elapsed(uint delta)
Test if a timer has elapsed.
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
int min_value
The minimal value this configuration setting can have.
const char * GetName() const
Get the Name of the script.
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.
static const NWidgetPart _nested_ai_settings_widgets[]
Widgets for the AI settings window.
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
static const int top_offset
Offset of the text at the top of the WID_AID_LOG_PANEL.
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
CompanyID slot
The company we're selecting a new Script for.
The company is manually removed.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
void ChangeAI()
Changes the AI of the current slot.
CompanyID slot
View the textfile of this CompanyID slot.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
LabelMapping * labels
Text labels for the integer values.
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.
void InitializeAIGui()
Reset the AI windows to their initial state.
DifficultySettings difficulty
settings related to the difficulty
static WindowDesc _ai_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_AI_LIST, WC_NONE, 0, _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets))
Window definition for the ai list window.
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.
Subdirectory for all game scripts.
Offset at top of a matrix cell.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
int max_value
The maximal value this configuration setting can have.
void ShowAIConfigWindow()
Open the AI config window.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
static const int bottom_offset
Offset of the text at the bottom of the WID_AID_LOG_PANEL.
#define lastof(x)
Get the last element of an fixed size array.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnResize() override
Called after the window got resized.
int last_vscroll_pos
Last position of the scrolling.
The AIInstance tracks an AI.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
AI debug window; Window numbers:
static T max(const T a, const T b)
Returns the maximum of two values.
void SelectValidDebugCompany()
Ensure that ai_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
All static information from an Game like name, version, etc.
int clicked_button
The button we clicked.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
void * GetLogPointer()
Get the log pointer of this script.
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.
Window that let you choose an available AI.
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
bool _network_available
is network mode available?
Force the alignment, i.e. don't swap for RTL languages.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void SetFilterTerm(const char *str)
Set the term to filter on.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
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...
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
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.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
The content consists of a game script.
bool closing_dropdown
True, if the dropdown list is currently closing.
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
CompanyID slot
The currently show company's setting.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Offset at bottom of a matrix cell.
int line_height
Height of a row in the matrix widget.
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.
AISettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
All static information from an Script like name, version, etc.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Data stored about a string that can be modified in the GUI.
ClientSettings _settings_client
The current settings for this game.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
int line_height
Height of a single AI-name line.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static const NWidgetPart _nested_ai_debug_widgets[]
Widgets for the AI debug window.
List of hotkeys for a window.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
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.
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
int selected
The currently selected Script.
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Window to configure which AIs will start.
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
uint step_height
Step-size of height resize changes.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
QueryString break_editbox
Break editbox.
Offset at left of a matrix cell.
static StringFilter break_string_filter
Log filter for break.
bool clicked_dropdown
Whether the dropdown is open.
int clicked_row
The clicked row of settings.
Window for settings the parameters of an AI.
Offset at bottom to draw the frame rectangular area.
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.
Window with everything an AI prints via ScriptLog.
static class GameInstance * GetInstance()
Get the current active instance.
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
const char * GetURL() const
Get the website for this script.
TextfileType
Additional text files accompanying Tar archives.
static T min(const T a, const T b)
Returns the minimum of two values.
NWidgetBase * MakeCompanyButtonRowsAIDebug(int *biggest_index)
Make a number of rows with buttons for each company for the AI debug window.
PauseMode _pause_mode
The current pause mode.
Left offset of the text of the frame.
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.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static const uint8 PC_BLACK
Black palette colour.
static class GameInfo * GetInfo()
Get the current GameInfo.
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.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
This value is a boolean (either 0 (false) or 1 (true) ).
void OnPaint() override
The window must be repainted.
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
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.
const char * description
The description of the configuration setting.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool IsDead() const
Return the "this script died" value.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
ScriptConfigFlags flags
Flags for the configuration setting.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
AIListWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
void OnPaint() override
The window must be repainted.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Scrollbar * vscroll
Cache of the vertical scrollbar.
char *const buf
buffer in which text is saved
const ScriptInfoList * info_list
The list of Scripts.
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
Scrollbar * vscroll
Cache of the vertical scrollbar.
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Window for displaying a textfile.
All static information from an AI like name, version, etc.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Info about a single Script setting.
Window for displaying the textfile of a AI.
void ChangeToAI(CompanyID show_ai)
Change all settings to select another AI.
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
The content consists of an AI.
VisibleSettingsList visible_settings
List of visible AI settings.
First company, same as owner.
TextDirection _current_text_dir
Text direction of the currently selected language.
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool show_break_box
Whether the break/debug box is visible.
Subdirectory for all AI files.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
static const NWidgetPart _nested_ai_list_widgets[]
Widgets for the AI list window.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Maximum number of companies.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
static void Unpause()
Resume execution of the Game Script.
This setting can be changed while the Script is running.
const char * GetAuthor() const
Get the Author of the script.
void OnResize() override
Called after the window got resized.
bool _network_server
network-server is active
Coordinates of a point in 2D.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
List item containing a C char string.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
byte max_no_competitors
the number of competitors (AIs)
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
bool clicked_increase
Whether we clicked the increase or decrease button.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
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)
AI settings; Window numbers:
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Offset at right to draw the frame rectangular area.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
int line_height
Height of a row in the matrix widget.
Base functions for all AIs.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
int32 WindowNumber
Number to differentiate different windows of the same class.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Specification of a rectangle with absolute coordinates of all edges.
bool IsShaded() const
Is window shaded currently?
Text is written right-to-left by default.
void OnResize() override
Called after the window got resized.
AIConfig stores the configuration settings of every AI.
AIInfo keeps track of all information of an AI, like Author, Description, ...
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Find a place automatically.
static bool case_sensitive_break_check
Is the matching done case-sensitive.
int step_size
The step size in the gui.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Errors (eg. saving/loading failed)
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
The object is owned by a superuser / goal script.
Dimensions (a width and height) of a rectangle in 2D.
Query string window; Window numbers:
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
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.
Game options window; Window numbers:
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.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
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.