12 #include "../stdafx.h" 13 #include "../table/sprites.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" 35 #include "../script/api/script_log.hpp" 39 #include "../game/game.hpp" 40 #include "../game/game_config.hpp" 41 #include "../game/game_info.hpp" 42 #include "../game/game_instance.hpp" 44 #include "table/strings.h" 48 #include "../safeguards.h" 84 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
91 for (ScriptInfoList::const_iterator it = this->info_list->begin(); it != this->info_list->end(); it++, i++) {
92 if ((*it).second == info) {
104 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
125 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
131 ScriptInfoList::const_iterator it = this->info_list->begin();
132 for (
int i = 1; it != this->info_list->end(); i++, it++) {
141 AIInfo *selected_info = NULL;
142 ScriptInfoList::const_iterator it = this->info_list->begin();
143 for (
int i = 1; selected_info == NULL && it != this->info_list->end(); i++, it++) {
144 if (this->selected == i - 1) selected_info =
static_cast<AIInfo *
>((*it).second);
147 if (selected_info != NULL) {
155 if (selected_info->
GetURL() != NULL) {
173 if (this->selected == -1) {
174 GetConfig(slot)->
Change(NULL);
176 ScriptInfoList::const_iterator it = this->info_list->begin();
177 for (
int i = 0; i < this->
selected; i++) it++;
178 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);
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++;
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;
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 == 0) {
574 this->clicked_button = -1;
586 this->RebuildVisibleSettings();
598 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),
615 _nested_ai_settings_widgets,
lengthof(_nested_ai_settings_widgets)
636 const char *textfile = GetConfig(slot)->
GetTextfile(file_type, slot);
673 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),
682 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),
688 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
700 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),
709 _nested_ai_config_widgets,
lengthof(_nested_ai_config_widgets)
744 switch (selected_slot) {
746 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
775 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
784 dim.width += padding.width;
785 dim.height += padding.height;
786 *size =
maxdim(*size, dim);
801 if (_game_mode != GM_NORMAL) {
810 return slot < max_slot;
821 text = STR_JUST_RAW_STRING;
836 text = STR_AI_CONFIG_HUMAN_PLAYER;
839 text = STR_JUST_RAW_STRING;
841 text = STR_AI_CONFIG_RANDOM_AI;
844 (this->selected_slot == i) ? TC_WHITE : (IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
855 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) == NULL)
return;
870 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
890 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot - 1))) {
892 this->selected_slot--;
899 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot + 1))) {
901 this->selected_slot++;
923 #if defined(ENABLE_NETWORK) 938 if (!IsEditable(this->selected_slot)) {
942 if (!gui_scope)
return;
951 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
976 Colours colour = dead ? COLOUR_RED :
977 (paused ? COLOUR_YELLOW : COLOUR_GREY);
978 if (button.
colour != colour) {
992 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1000 static char break_string[MAX_BREAK_STR_STRING_LENGTH];
1007 ScriptLog::LogData *GetLogPointer()
const 1010 return (ScriptLog::LogData *)
Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1021 return game == NULL || game->
IsDead();
1047 if (this->IsValidDebugCompany(ai_debug_company))
return;
1052 FOR_ALL_COMPANIES(c) {
1054 ChangeToAI(c->
index);
1076 if (!this->show_break_box) break_check_enabled =
false;
1078 this->last_vscroll_pos = 0;
1079 this->autoscroll =
true;
1080 this->highlight_row = -1;
1087 this->break_editbox.text.
Assign(this->break_string);
1089 this->SelectValidDebugCompany();
1097 size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1103 this->SelectValidDebugCompany();
1122 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
1123 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
1129 if (!valid)
continue;
1131 byte offset = (i == ai_debug_company) ? 1 : 0;
1137 bool valid = game != NULL;
1138 bool dead = valid && game->
IsDead();
1139 bool paused = valid && game->
IsPaused();
1149 ScriptLog::LogData *log = this->GetLogPointer();
1151 int scroll_count = (log == NULL) ? 0 : log->used;
1152 if (this->vscroll->
GetCount() != scroll_count) {
1153 this->vscroll->
SetCount(scroll_count);
1159 if (log == NULL)
return;
1163 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1166 if (this->autoscroll) {
1167 int scroll_pos =
max(0, log->used - this->vscroll->GetCapacity());
1176 this->last_vscroll_pos = this->vscroll->
GetPosition();
1185 assert(info != NULL);
1186 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1193 assert(info != NULL);
1194 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1208 ScriptLog::LogData *log = this->GetLogPointer();
1209 if (log == NULL)
return;
1211 int y = this->top_offset;
1212 for (
int i = this->vscroll->
GetPosition(); this->vscroll->
IsVisible(i) && i < log->used; i++) {
1213 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1214 if (log->lines[pos] == NULL)
break;
1217 switch (log->type[pos]) {
1218 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1219 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1220 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1221 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1222 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1223 default: colour = TC_BLACK;
break;
1227 if (pos == this->highlight_row) {
1229 if (colour == TC_BLACK) colour = TC_WHITE;
1246 if (!this->IsValidDebugCompany(show_ai))
return;
1248 ai_debug_company = show_ai;
1250 this->highlight_row = -1;
1257 this->autoscroll =
true;
1258 this->last_vscroll_pos = this->vscroll->
GetPosition();
1288 this->break_check_enabled = !this->break_check_enabled;
1293 this->case_sensitive_break_check = !this->case_sensitive_break_check;
1299 if (!this->IsDead()) {
1312 FOR_ALL_COMPANIES(c) {
1314 all_unpaused =
false;
1325 this->highlight_row = -1;
1335 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1350 if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.
IsEmpty()) {
1352 ScriptLog::LogData *log = this->GetLogPointer();
1356 this->break_string_filter.
AddLine(log->lines[log->pos]);
1357 if (this->break_string_filter.
GetState()) {
1359 if (!this->IsDead()) {
1373 this->highlight_row = log->pos;
1378 if (!gui_scope)
return;
1380 this->SelectValidDebugCompany();
1382 ScriptLog::LogData *log = ai_debug_company !=
INVALID_COMPANY ? this->GetLogPointer() : NULL;
1383 this->vscroll->
SetCount((log == NULL) ? 0 : log->used);
1438 static Hotkey aidebug_hotkeys[] = {
1495 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),
1512 WDP_AUTO,
"script_debug", 600, 450,
1515 _nested_ai_debug_widgets,
lengthof(_nested_ai_debug_widgets),
1516 &AIDebugWindow::hotkeys
1552 FOR_ALL_COMPANIES(c) {
1560 if (g != NULL && g->
IsDead()) {
EventState
State of handling an event.
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.
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.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
virtual void OnPaint()
The window must be repainted.
All data for a single hotkey.
High level window description.
static void Unpause(CompanyID company)
Resume execution of the AI.
const Pair * Find(const T &key) const
Finds given key in this map.
void DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
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.
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.
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.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
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.
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.
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
Tindex index
Index of this pool item.
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.
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.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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.
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?
T * Append(uint to_add=1)
Append an item and return it.
Force the alignment, i.e. don't swap for RTL languages.
The object is owned by a superuser / goal script.
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.
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.
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.
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.
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.
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...
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
All static information from an Script like name, version, etc.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void OnResize()
Called after the window got resized.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
int line_height
Height of a single AI-name line.
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.
First company, same as owner.
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
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.
PauseModeByte _pause_mode
The current pause mode.
TextfileType
Additional text files accompanying Tar archives.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
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.
int timeout
Timeout for unclicking the button.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
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.
Maximum number of companies.
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 AddLine(const char *str)
Pass another text line from the current item to the filter.
bool IsDead() const
Return the "this script died" value.
virtual void OnResize()
Called after the window got resized.
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.
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 SetStringParameters(int widget) const
Initialize string parameters for a widget.
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.
virtual void OnTick()
Called once per (game) tick.
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.
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
Scrollbar * vscroll
Cache of the vertical scrollbar.
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.
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.
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 ...
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.
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.
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.
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.
bool _network_server
network-server is active
Coordinates of a point in 2D.
List item containing a C char string.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
virtual void OnResize()
Called after the window got resized.
byte max_no_competitors
the number of competitors (AIs)
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
bool clicked_increase
Whether we clicked the increase or decrease button.
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 void SetStringParameters(int widget) const
Initialize string parameters for a widget.
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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
AIConfig stores the configuration settings of every AI.
Owner
Enum for all companies/owners.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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)
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
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:
virtual void OnPaint()
The window must be repainted.
void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
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 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?
AutoDeleteSmallVector< const DropDownListItem *, 4 > DropDownList
A drop down list is a collection of drop down list items.
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.