Go to the documentation of this file.
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"
31 #include "../company_cmd.h"
32 #include "../misc_cmd.h"
36 #include "../script/api/script_log.hpp"
40 #include "../game/game.hpp"
41 #include "../game/game_config.hpp"
42 #include "../game/game_info.hpp"
43 #include "../game/game_instance.hpp"
45 #include "table/strings.h"
49 #include "../safeguards.h"
85 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
89 if (GetConfig(
slot)->HasScript()) {
92 for (
const auto &item : *this->info_list) {
93 if (item.second == info) {
107 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
131 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
135 for (
const auto &item : *this->info_list) {
138 DrawString(tr, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
147 for (
const auto &item : *this->info_list) {
149 if (this->selected == i - 1) selected_info =
static_cast<ScriptInfo *
>(item.second);
152 if (selected_info !=
nullptr) {
160 if (selected_info->
GetURL() !=
nullptr) {
178 if (this->selected == -1) {
181 ScriptInfoList::const_iterator it = this->info_list->begin();
182 for (
int i = 0; i < this->
selected; i++) it++;
183 GetConfig(
slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
196 if (sel < (
int)this->info_list->size()) {
197 this->selected = sel;
199 if (click_count > 1) {
236 if (!gui_scope)
return;
238 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
241 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
253 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),
314 this->ai_config = GetConfig(
slot);
330 visible_settings.clear();
339 this->vscroll->
SetCount((
int)this->visible_settings.size());
358 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
360 for (; !this->vscroll->
IsVisible(i); i++) it++;
372 int current_value = config->
GetSetting((config_item).name);
373 bool editable = this->IsEditableItem(config_item);
379 if (!strcmp(config_item.
name,
"start_date")) {
381 str = STR_AI_SETTINGS_START_DELAY;
382 colour = TC_LIGHT_BLUE;
384 str = STR_JUST_STRING;
388 str = STR_AI_SETTINGS_SETTING;
389 colour = TC_LIGHT_BLUE;
394 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
395 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
400 DrawArrowButtons(br.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);
411 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
418 if (this->closing_dropdown) {
419 this->closing_dropdown =
false;
420 this->clicked_dropdown =
false;
430 int num = (pt.y - r.top) / this->line_height + this->vscroll->
GetPosition();
431 if (num >= (
int)this->visible_settings.size())
break;
433 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
434 for (
int i = 0; i < num; i++) it++;
436 if (!this->IsEditableItem(config_item))
return;
438 if (this->clicked_row != num) {
441 this->clicked_row = num;
442 this->clicked_dropdown =
false;
447 int x = pt.x - r.left;
453 if (this->clicked_dropdown) {
456 this->clicked_dropdown =
false;
457 this->closing_dropdown =
false;
459 int rel_y = (pt.y - r.top) % this->line_height;
468 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
469 this->clicked_dropdown =
true;
470 this->closing_dropdown =
false;
481 int new_val = old_val;
488 this->clicked_increase =
true;
493 this->clicked_increase =
false;
496 if (new_val != old_val) {
498 this->clicked_button = num;
499 this->timeout.SetInterval(150);
524 int32 value = atoi(str);
531 assert(this->clicked_dropdown);
541 assert(this->clicked_dropdown);
542 this->closing_dropdown =
true;
553 if (this->timeout.
Elapsed(delta_ms)) {
554 this->clicked_button = -1;
574 return _game_mode == GM_MENU
575 || _game_mode == GM_EDITOR
581 void SetValue(
int value)
583 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
600 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),
652 if (textfile ==
nullptr) {
693 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),
708 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_AIC_CONTENT_DOWNLOAD),
SetFill(1, 0),
SetMinimalSize(279, 0),
SetPadding(0, 7, 9, 7),
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
760 *size =
maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
778 if (_game_mode != GM_NORMAL) {
787 return slot < max_slot;
799 text = STR_AI_CONFIG_HUMAN_PLAYER;
802 text = STR_JUST_RAW_STRING;
804 text = STR_AI_CONFIG_RANDOM_AI;
807 (this->selected_slot == i) ? TC_WHITE : (
IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
818 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) ==
nullptr)
return;
829 new_value = std::max(0,
GetGameSettings().difficulty.max_no_competitors - 1);
833 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
847 this->selected_slot--;
856 this->selected_slot++;
895 if (!gui_scope)
return;
904 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
929 Colours colour = dead ? COLOUR_RED :
930 (paused ? COLOUR_YELLOW : COLOUR_GREY);
931 if (button.
colour != colour) {
957 ScriptLog::LogData *GetLogPointer()
const
971 return game ==
nullptr || game->
IsDead();
1027 this->last_vscroll_pos = 0;
1028 this->autoscroll =
true;
1029 this->highlight_row = -1;
1036 this->break_editbox.text.
Assign(this->break_string);
1078 if (!
valid)
continue;
1086 bool valid = game !=
nullptr;
1098 ScriptLog::LogData *log = this->GetLogPointer();
1100 int scroll_count = (log ==
nullptr) ? 0 : log->used;
1101 if (this->vscroll->
GetCount() != scroll_count) {
1102 this->vscroll->
SetCount(scroll_count);
1108 if (log ==
nullptr)
return;
1112 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1115 if (this->autoscroll) {
1116 int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1123 this->last_vscroll_pos = this->vscroll->
GetPosition();
1132 assert(info !=
nullptr);
1133 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1140 assert(info !=
nullptr);
1141 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1155 ScriptLog::LogData *log = this->GetLogPointer();
1156 if (log ==
nullptr)
return;
1160 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1161 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1162 if (log->lines[pos] ==
nullptr)
break;
1165 switch (log->type[pos]) {
1166 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1167 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1168 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1169 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1170 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1171 default: colour = TC_BLACK;
break;
1175 if (pos == this->highlight_row) {
1177 if (colour == TC_BLACK) colour = TC_WHITE;
1198 this->highlight_row = -1;
1205 this->autoscroll =
true;
1206 this->last_vscroll_pos = this->vscroll->
GetPosition();
1261 all_unpaused =
false;
1272 this->highlight_row = -1;
1282 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1299 ScriptLog::LogData *log = this->GetLogPointer();
1301 if (log !=
nullptr) {
1303 this->break_string_filter.
AddLine(log->lines[log->pos]);
1304 if (this->break_string_filter.
GetState()) {
1320 this->highlight_row = log->pos;
1325 if (!gui_scope)
return;
1330 this->vscroll->
SetCount((log ==
nullptr) ? 0 : log->used);
1384 static Hotkey aidebug_hotkeys[] = {
1441 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),
1458 WDP_AUTO,
"script_debug", 600, 450,
1462 &AIDebugWindow::hotkeys
1498 if (c->is_ai && c->ai_instance->IsDead()) {
1505 if (g !=
nullptr && g->
IsDead()) {
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
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 constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
static bool IsPaused()
Checks if the Game Script is paused.
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.
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
static Titem * Get(size_t index)
Returns Titem with given index.
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
const char * GetAuthor() const
Get the Author of the script.
GUITimer timeout
Timeout for unclicking the button.
@ CRR_NONE
Dummy reason for actions that don't need one.
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
NWidgetBase * MakeCompanyButtonRowsAIDebug(int *biggest_index)
Make a number of rows with buttons for each company for the AI debug window.
@ INVALID_CLIENT_ID
Client is not part of anything.
List of hotkeys for a window.
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.
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
static const NWidgetPart _nested_ai_list_widgets[]
Widgets for the AI list window.
void SelectValidDebugCompany()
Ensure that ai_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
Dimensions (a width and height) of a rectangle in 2D.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Window that let you choose an available AI.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int step_size
The step size in the gui.
bool IsEmpty() const
Check whether any filter words were entered.
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
void OnResize() override
Called after the window got resized.
void OnResize() override
Called after the window got resized.
@ CCA_DELETE
Delete a company.
void SetFilterTerm(const char *str)
Set the term to filter on.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
int clicked_button
The button we clicked.
LabelMapping * labels
Text labels for the integer values.
bool _network_server
network-server is active
void Assign(StringID string)
Render a string into the textbuffer.
void OnPaint() override
The window must be repainted.
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.
static class GameInfo * GetInfo()
Get the current GameInfo.
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.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static StringFilter break_string_filter
Log filter for break.
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.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
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.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
DifficultySettings difficulty
settings related to the difficulty
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
const char * GetURL() const
Get the website for this script.
ClientSettings _settings_client
The current settings for this game.
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.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
int line_height
Height of a row in the matrix widget.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
int32 WindowNumber
Number to differentiate different windows of the same class.
static void Unpause()
Resume execution of the Game Script.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Owner
Enum for all companies/owners.
TextfileType file_type
Type of textfile to view.
@ TFT_CHANGELOG
NewGRF changelog.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
const char * GetDescription() const
Get the description of the script.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Data stored about a string that can be modified in the GUI.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
int min_value
The minimal value this configuration setting can have.
char *const buf
buffer in which text is saved
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.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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.
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.
int highlight_row
The output row that matches the given string, or -1.
@ PM_UNPAUSED
A normal unpaused game.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
int last_vscroll_pos
Last position of the scrolling.
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
High level window description.
bool complete_labels
True if all values have a label.
@ COMPANY_FIRST
First company, same as owner.
static void Unpause(CompanyID company)
Resume execution of the AI.
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
@ WC_QUERY_STRING
Query string window; Window numbers:
bool ai_developer_tools
activate AI/GS developer tools
int max_value
The maximal value this configuration setting can have.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
@ WDP_AUTO
Find a place automatically.
bool clicked_dropdown
Whether the dropdown is open.
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
ResizeInfo resize
Resize information.
static bool case_sensitive_break_check
Is the matching done case-sensitive.
AIListWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
@ AI_DIR
Subdirectory for all AI files.
static const NWidgetPart _nested_ai_debug_widgets[]
Widgets for the AI debug window.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Scrollbar * vscroll
Cache of the vertical scrollbar.
void ChangeAI()
Changes the AI of the current slot.
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
const ScriptInfoList * info_list
The list of Scripts.
@ ES_NOT_HANDLED
The passed event is not handled.
CompanyID slot
The currently show company's setting.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
bool IsDead() const
Return the "this script died" value.
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.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
PauseMode _pause_mode
The current pause mode.
static const NWidgetPart _nested_ai_settings_widgets[]
Widgets for the AI settings window.
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
int line_height
Height of a single AI-name line.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
static WindowDesc _ai_config_desc(WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
Window definition for the configure AI window.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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 bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
@ GAME_DIR
Subdirectory for all game scripts.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
bool closing_dropdown
True, if the dropdown list is currently closing.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
Coordinates of a point in 2D.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
Window for displaying the textfile of a AI.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ CRR_MANUAL
The company is manually removed.
Scrollbar * vscroll
Cache of the vertical scrollbar.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
AISettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
static const uint8 PC_BLACK
Black palette colour.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
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.
uint step_height
Step-size of height resize changes.
uint Vertical() const
Get total vertical padding of RectPadding.
Scrollbar * vscroll
Cache of the vertical scrollbar.
bool show_break_box
Whether the break/debug box is visible.
@ TFT_README
NewGRF readme.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Scrollbar * vscroll
Cache of the vertical scrollbar.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ CCA_NEW_AI
Create a new AI company.
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Window with everything an AI prints via ScriptLog.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Runtime information about a game script like a pointer to the squirrel vm and the current state.
@ CONTENT_TYPE_AI
The content consists of an AI.
@ TFT_LICENSE
NewGRF license.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void ChangeToAI(CompanyID show_ai)
Change all settings to select another AI.
Window to configure which AIs will start.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_AI_DEBUG
AI debug window; Window numbers:
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
bool IsShaded() const
Is window shaded currently?
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.
int GetVersion() const
Get the version of the script.
VisibleSettingsList visible_settings
List of visible AI settings.
const char * description
The description of the configuration setting.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
@ WC_AI_LIST
AI list; Window numbers:
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
CompanyID slot
The company we're selecting a new Script for.
int clicked_row
The clicked row of settings.
static bool break_check_enabled
Stop an AI when it prints a matching string.
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
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 InitializeAIGui()
Reset the AI windows to their initial state.
void ResetState()
Reset the matching state to process a new item.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
@ WC_AI_SETTINGS
AI settings; Window numbers:
@ PM_PAUSED_NORMAL
A game normally paused.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
EventState
State of handling an event.
All static information from an Game like name, version, etc.
@ WN_GAME_OPTIONS_GS
GS settings.
bool GetState() const
Get the matching state of the current item.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
CompanyID slot
View the textfile of this CompanyID slot.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
byte max_no_competitors
the number of competitors (AIs)
@ WL_ERROR
Errors (eg. saving/loading failed)
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
bool Elapsed(uint delta)
Test if a timer has elapsed.
@ WN_GAME_OPTIONS_AI
AI settings.
@ SA_LEFT
Left align the text.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
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.
#define lengthof(x)
Return the length of an fixed size array.
void OnPaint() override
The window must be repainted.
QueryString break_editbox
Break editbox.
All static information from an AI like name, version, etc.
ScriptConfigFlags flags
Flags for the configuration setting.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
@ INVALID_COMPANY
An invalid company.
bool IsPaused()
Checks if the script is paused.
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.
Window for displaying a textfile.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Data structure for an opened window.
TextfileType
Additional text files accompanying Tar archives.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
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.
int selected
The currently selected Script.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
void DrawWidgets() const
Paint all widgets of a window.
const char * GetName() const
Get the Name of the script.
Window for settings the parameters of an AI.
void OnResize() override
Called after the window got resized.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
static void Swap(T &a, T &b)
Type safe swap operation.
bool _network_available
is network mode available?
int Width() const
Get width of Rect.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
void ShowAIConfigWindow()
Open the AI config window.
All static information from an Script like name, version, etc.
static class GameInstance * GetInstance()
Get the current active instance.
Specification of a rectangle with absolute coordinates of all edges.
ScriptConfig * ai_config
The configuration we're modifying.
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Info about a single Script setting.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
const char * name
The name of the configuration setting.
@ WC_TEXTFILE
textfile; Window numbers:
#define lastof(x)
Get the last element of an fixed size array.
void * GetLogPointer()
Get the log pointer of this script.
@ WDP_CENTER
Center the window.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
bool autoscroll
Whether automatically scrolling should be enabled or not.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
All data for a single hotkey.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
bool clicked_increase
Whether we clicked the increase or decrease button.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
int line_height
Height of a row in the matrix widget.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.