|
OpenTTD Source
13.0-beta1
|
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);
128 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
135 for (
const auto &item : *this->info_list) {
145 AIInfo *selected_info =
nullptr;
147 for (
const auto &item : *this->info_list) {
149 if (this->selected == i - 1) selected_info =
static_cast<AIInfo *
>(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),
299 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
314 this->ai_config = GetConfig(
slot);
327 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
348 this->vscroll->
SetCount((
int)this->visible_settings.size());
367 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
369 for (; !this->vscroll->
IsVisible(i); i++) it++;
382 int current_value = config->
GetSetting((config_item).name);
383 bool editable = this->IsEditableItem(config_item);
389 if (!strcmp(config_item.
name,
"start_date")) {
391 str = STR_AI_SETTINGS_START_DELAY;
392 colour = TC_LIGHT_BLUE;
394 str = STR_JUST_STRING;
398 str = STR_AI_SETTINGS_SETTING;
399 colour = TC_LIGHT_BLUE;
404 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
405 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
410 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);
421 DrawString(text_left, text_right, y + text_y_offset, str, colour);
428 if (this->closing_dropdown) {
429 this->closing_dropdown =
false;
430 this->clicked_dropdown =
false;
440 int num = (pt.y - wid->
pos_y) / this->line_height + this->vscroll->
GetPosition();
441 if (num >= (
int)this->visible_settings.size())
break;
443 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
444 for (
int i = 0; i < num; i++) it++;
446 if (!this->IsEditableItem(config_item))
return;
448 if (this->clicked_row != num) {
451 this->clicked_row = num;
452 this->clicked_dropdown =
false;
457 int x = pt.x - wid->
pos_x;
464 if (this->clicked_dropdown) {
467 this->clicked_dropdown =
false;
468 this->closing_dropdown =
false;
480 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
481 this->clicked_dropdown =
true;
482 this->closing_dropdown =
false;
493 int new_val = old_val;
500 this->clicked_increase =
true;
505 this->clicked_increase =
false;
508 if (new_val != old_val) {
510 this->clicked_button = num;
511 this->timeout.SetInterval(150);
536 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
540 int32 value = atoi(str);
547 assert(this->clicked_dropdown);
548 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
562 assert(this->clicked_dropdown);
563 this->closing_dropdown =
true;
574 if (this->timeout.
Elapsed(delta_ms)) {
575 this->clicked_button = -1;
607 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_AIS_SCROLLBAR),
659 if (textfile ==
nullptr) {
700 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),
706 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
718 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),
765 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
785 *size =
maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
800 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
809 dim.width += padding.width;
810 dim.height += padding.height;
811 *size =
maxdim(*size, dim);
826 if (_game_mode != GM_NORMAL) {
835 return slot < max_slot;
846 text = STR_JUST_RAW_STRING;
861 text = STR_AI_CONFIG_HUMAN_PLAYER;
864 text = STR_JUST_RAW_STRING;
866 text = STR_AI_CONFIG_RANDOM_AI;
869 (this->selected_slot == i) ? TC_WHITE : (
IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
880 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) ==
nullptr)
return;
891 new_value = std::max(0,
GetGameSettings().difficulty.max_no_competitors - 1);
895 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
916 this->selected_slot--;
925 this->selected_slot++;
964 if (!gui_scope)
return;
973 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
998 Colours colour = dead ? COLOUR_RED :
999 (paused ? COLOUR_YELLOW : COLOUR_GREY);
1000 if (button.
colour != colour) {
1029 ScriptLog::LogData *GetLogPointer()
const
1043 return game ==
nullptr || game->
IsDead();
1099 this->last_vscroll_pos = 0;
1100 this->autoscroll =
true;
1101 this->highlight_row = -1;
1108 this->break_editbox.text.
Assign(this->break_string);
1150 if (!
valid)
continue;
1158 bool valid = game !=
nullptr;
1170 ScriptLog::LogData *log = this->GetLogPointer();
1172 int scroll_count = (log ==
nullptr) ? 0 : log->used;
1173 if (this->vscroll->
GetCount() != scroll_count) {
1174 this->vscroll->
SetCount(scroll_count);
1180 if (log ==
nullptr)
return;
1184 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1187 if (this->autoscroll) {
1188 int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
1197 this->last_vscroll_pos = this->vscroll->
GetPosition();
1206 assert(info !=
nullptr);
1207 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1214 assert(info !=
nullptr);
1215 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1229 ScriptLog::LogData *log = this->GetLogPointer();
1230 if (log ==
nullptr)
return;
1233 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
1234 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1235 if (log->lines[pos] ==
nullptr)
break;
1238 switch (log->type[pos]) {
1239 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1240 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1241 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1242 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1243 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1244 default: colour = TC_BLACK;
break;
1248 if (pos == this->highlight_row) {
1250 if (colour == TC_BLACK) colour = TC_WHITE;
1271 this->highlight_row = -1;
1278 this->autoscroll =
true;
1279 this->last_vscroll_pos = this->vscroll->
GetPosition();
1334 all_unpaused =
false;
1345 this->highlight_row = -1;
1355 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1372 ScriptLog::LogData *log = this->GetLogPointer();
1374 if (log !=
nullptr) {
1376 this->break_string_filter.
AddLine(log->lines[log->pos]);
1377 if (this->break_string_filter.
GetState()) {
1393 this->highlight_row = log->pos;
1398 if (!gui_scope)
return;
1403 this->vscroll->
SetCount((log ==
nullptr) ? 0 : log->used);
1459 static Hotkey aidebug_hotkeys[] = {
1516 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),
1533 WDP_AUTO,
"script_debug", 600, 450,
1537 &AIDebugWindow::hotkeys
1573 if (c->is_ai && c->ai_instance->IsDead()) {
1580 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 constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
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.
@ CRR_NONE
Dummy reason for actions that don't need one.
@ 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.
@ 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 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.
@ CCA_DELETE
Delete a company.
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.
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.
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)
@ 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.
@ CRR_MANUAL
The company is manually removed.
Scrollbar * vscroll
Cache of the vertical scrollbar.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
@ 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.
@ 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.
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.
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.
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.