OpenTTD Source
12.0-beta2
|
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"
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);
87 if (GetConfig(
slot)->HasScript()) {
90 for (
const auto &item : *this->info_list) {
91 if (item.second == info) {
105 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
126 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
133 for (
const auto &item : *this->info_list) {
143 AIInfo *selected_info =
nullptr;
145 for (
const auto &item : *this->info_list) {
147 if (this->selected == i - 1) selected_info =
static_cast<AIInfo *
>(item.second);
150 if (selected_info !=
nullptr) {
158 if (selected_info->
GetURL() !=
nullptr) {
176 if (this->selected == -1) {
179 ScriptInfoList::const_iterator it = this->info_list->begin();
180 for (
int i = 0; i < this->
selected; i++) it++;
181 GetConfig(
slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
194 if (sel < (
int)this->info_list->size()) {
195 this->selected = sel;
197 if (click_count > 1) {
234 if (!gui_scope)
return;
236 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
239 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
251 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIL_LIST),
SetMinimalSize(188, 112),
SetFill(1, 1),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP),
SetScrollbar(
WID_AIL_SCROLLBAR),
297 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
312 this->ai_config = GetConfig(
slot);
325 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
346 this->vscroll->
SetCount((
int)this->visible_settings.size());
365 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
367 for (; !this->vscroll->
IsVisible(i); i++) it++;
380 int current_value = config->
GetSetting((config_item).name);
381 bool editable = this->IsEditableItem(config_item);
387 if (!strcmp(config_item.
name,
"start_date")) {
389 str = STR_AI_SETTINGS_START_DELAY;
390 colour = TC_LIGHT_BLUE;
392 str = STR_JUST_STRING;
396 str = STR_AI_SETTINGS_SETTING;
397 colour = TC_LIGHT_BLUE;
402 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
403 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
408 DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.
min_value, editable && current_value < config_item.
max_value);
419 DrawString(text_left, text_right, y + text_y_offset, str, colour);
426 if (this->closing_dropdown) {
427 this->closing_dropdown =
false;
428 this->clicked_dropdown =
false;
438 int num = (pt.y - wid->
pos_y) / this->line_height + this->vscroll->
GetPosition();
439 if (num >= (
int)this->visible_settings.size())
break;
441 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
442 for (
int i = 0; i < num; i++) it++;
444 if (!this->IsEditableItem(config_item))
return;
446 if (this->clicked_row != num) {
449 this->clicked_row = num;
450 this->clicked_dropdown =
false;
455 int x = pt.x - wid->
pos_x;
462 if (this->clicked_dropdown) {
465 this->clicked_dropdown =
false;
466 this->closing_dropdown =
false;
478 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
479 this->clicked_dropdown =
true;
480 this->closing_dropdown =
false;
491 int new_val = old_val;
498 this->clicked_increase =
true;
503 this->clicked_increase =
false;
506 if (new_val != old_val) {
508 this->clicked_button = num;
509 this->timeout.SetInterval(150);
534 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
538 int32 value = atoi(str);
545 assert(this->clicked_dropdown);
546 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
560 assert(this->clicked_dropdown);
561 this->closing_dropdown =
true;
572 if (this->timeout.
Elapsed(delta_ms)) {
573 this->clicked_button = -1;
605 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_AIS_SCROLLBAR),
657 if (textfile ==
nullptr) {
689 NWidget(
WWT_TEXT, COLOUR_MAUVE,
WID_AIC_NUMBER),
SetDataTip(STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS, STR_NULL),
SetFill(1, 0),
SetPadding(1, 0, 0, 0),
698 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_LIST),
SetMinimalSize(288, 112),
SetFill(1, 0),
SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP),
SetScrollbar(
WID_AIC_SCROLLBAR),
704 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
716 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_AIC_CONTENT_DOWNLOAD),
SetFill(1, 0),
SetMinimalSize(279, 0),
SetPadding(0, 7, 9, 7),
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
763 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
793 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
802 dim.width += padding.width;
803 dim.height += padding.height;
804 *size =
maxdim(*size, dim);
819 if (_game_mode != GM_NORMAL) {
828 return slot < max_slot;
839 text = STR_JUST_RAW_STRING;
854 text = STR_AI_CONFIG_HUMAN_PLAYER;
857 text = STR_JUST_RAW_STRING;
859 text = STR_AI_CONFIG_RANDOM_AI;
862 (this->selected_slot == i) ? TC_WHITE : (
IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
873 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) ==
nullptr)
return;
884 new_value = std::max(0,
GetGameSettings().difficulty.max_no_competitors - 1);
888 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
909 this->selected_slot--;
918 this->selected_slot++;
957 if (!gui_scope)
return;
966 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
991 Colours colour = dead ? COLOUR_RED :
992 (paused ? COLOUR_YELLOW : COLOUR_GREY);
993 if (button.
colour != colour) {
1022 ScriptLog::LogData *GetLogPointer()
const
1036 return game ==
nullptr || game->
IsDead();
1092 this->last_vscroll_pos = 0;
1093 this->autoscroll =
true;
1094 this->highlight_row = -1;
1101 this->break_editbox.text.
Assign(this->break_string);
1143 if (!
valid)
continue;
1151 bool valid = game !=
nullptr;
1163 ScriptLog::LogData *log = this->GetLogPointer();
1165 int scroll_count = (log ==
nullptr) ? 0 : log->used;
1166 if (this->vscroll->
GetCount() != scroll_count) {
1167 this->vscroll->
SetCount(scroll_count);
1173 if (log ==
nullptr)
return;
1177 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1180 if (this->autoscroll) {
1181 int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1190 this->last_vscroll_pos = this->vscroll->
GetPosition();
1199 assert(info !=
nullptr);
1200 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1207 assert(info !=
nullptr);
1208 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1222 ScriptLog::LogData *log = this->GetLogPointer();
1223 if (log ==
nullptr)
return;
1226 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1227 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1228 if (log->lines[pos] ==
nullptr)
break;
1231 switch (log->type[pos]) {
1232 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1233 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1234 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1235 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1236 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1237 default: colour = TC_BLACK;
break;
1241 if (pos == this->highlight_row) {
1243 if (colour == TC_BLACK) colour = TC_WHITE;
1264 this->highlight_row = -1;
1271 this->autoscroll =
true;
1272 this->last_vscroll_pos = this->vscroll->
GetPosition();
1327 all_unpaused =
false;
1338 this->highlight_row = -1;
1348 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1365 ScriptLog::LogData *log = this->GetLogPointer();
1367 if (log !=
nullptr) {
1369 this->break_string_filter.
AddLine(log->lines[log->pos]);
1370 if (this->break_string_filter.
GetState()) {
1386 this->highlight_row = log->pos;
1391 if (!gui_scope)
return;
1396 this->vscroll->
SetCount((log ==
nullptr) ? 0 : log->used);
1452 static Hotkey aidebug_hotkeys[] = {
1509 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_AID_BREAK_STR_EDIT_BOX),
SetFill(1, 1),
SetResize(1, 0),
SetPadding(2, 2, 2, 2),
SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1526 WDP_AUTO,
"script_debug", 600, 450,
1530 &AIDebugWindow::hotkeys
1566 if (c->is_ai && c->ai_instance->IsDead()) {
1573 if (g !=
nullptr && g->
IsDead()) {
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
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 const int top_offset
Offset of the text at the top of the WID_AID_LOG_PANEL.
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.
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
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.
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 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.
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.
void SetFilterTerm(const char *str)
Set the term to filter on.
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
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.
Owner
Enum for all companies/owners.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
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) ).
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
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?
@ CONTENT_TYPE_GAME
The content consists of a game script.
@ WC_QUERY_STRING
Query string window; Window numbers:
bool ai_developer_tools
activate AI 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.
@ 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.
@ CCA_NEW_AI
Create a new AI company.
static bool case_sensitive_break_check
Is the matching done case-sensitive.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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.
@ CMD_PAUSE
pause the game
@ 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)
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
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.
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
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.
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.
Scrollbar * vscroll
Cache of the vertical scrollbar.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
@ CRR_MANUAL
The company is manually removed.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
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.
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.
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.
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
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.
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.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
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.
static const int bottom_offset
Offset of the text at the bottom of the WID_AID_LOG_PANEL.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
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.
@ CCA_DELETE
Delete a company.
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.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
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?
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.
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.
@ CS_NUMERAL
Only numeric ones.
static void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
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.