12 #include "../stdafx.h" 13 #include "../table/sprites.h" 15 #include "../settings_gui.h" 16 #include "../querystring_gui.h" 17 #include "../stringfilter_type.h" 18 #include "../company_base.h" 19 #include "../company_gui.h" 20 #include "../strings_func.h" 21 #include "../window_func.h" 22 #include "../gfx_func.h" 23 #include "../command_func.h" 24 #include "../network/network.h" 25 #include "../settings_func.h" 26 #include "../network/network_content.h" 27 #include "../textfile_gui.h" 28 #include "../widgets/dropdown_type.h" 29 #include "../widgets/dropdown_func.h" 30 #include "../hotkeys.h" 31 #include "../core/geometry_func.hpp" 32 #include "../guitimer_func.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);
92 for (ScriptInfoList::const_iterator it = this->info_list->begin(); it != this->info_list->end(); it++, i++) {
93 if ((*it).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;
132 ScriptInfoList::const_iterator it = this->info_list->begin();
133 for (
int i = 1; it != this->info_list->end(); i++, it++) {
142 AIInfo *selected_info = NULL;
143 ScriptInfoList::const_iterator it = this->info_list->begin();
144 for (
int i = 1; selected_info == NULL && it != this->info_list->end(); i++, it++) {
145 if (this->selected == i - 1) selected_info =
static_cast<AIInfo *
>((*it).second);
148 if (selected_info != NULL) {
156 if (selected_info->
GetURL() != NULL) {
174 if (this->selected == -1) {
175 GetConfig(slot)->
Change(NULL);
177 ScriptInfoList::const_iterator it = this->info_list->begin();
178 for (
int i = 0; i < this->
selected; i++) it++;
179 GetConfig(slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
191 if (sel < (
int)this->info_list->size()) {
192 this->selected = sel;
194 if (click_count > 1) {
231 if (!gui_scope)
return;
233 this->vscroll->
SetCount((
int)this->info_list->size() + 1);
236 this->selected =
min(this->selected, this->vscroll->
GetCount() - 2);
248 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),
267 _nested_ai_list_widgets,
lengthof(_nested_ai_list_widgets)
294 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
305 clicked_dropdown(false),
306 closing_dropdown(false),
309 this->ai_config = GetConfig(slot);
317 this->RebuildVisibleSettings();
324 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
336 visible_settings.clear();
338 ScriptConfigItemList::const_iterator it = this->ai_config->
GetConfigList()->begin();
339 for (; it != this->ai_config->
GetConfigList()->end(); it++) {
342 visible_settings.push_back(&(*it));
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++;
378 for (; this->vscroll->
IsVisible(i) && it != visible_settings.end(); 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);
406 DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
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);
536 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
537 for (
int i = 0; i < this->clicked_row; i++) it++;
540 int32 value = atoi(str);
547 assert(this->clicked_dropdown);
548 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
549 for (
int i = 0; i < this->clicked_row; i++) it++;
562 assert(this->clicked_dropdown);
563 this->closing_dropdown =
true;
574 if (this->timeout.
Elapsed(delta_ms)) {
575 this->clicked_button = -1;
587 this->RebuildVisibleSettings();
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),
624 _nested_ai_settings_widgets,
lengthof(_nested_ai_settings_widgets)
645 const char *textfile = GetConfig(slot)->
GetTextfile(file_type, slot);
682 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),
691 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),
697 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
709 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_AIC_CONTENT_DOWNLOAD),
SetFill(1, 0),
SetMinimalSize(279, 12),
SetPadding(0, 7, 9, 7),
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
718 _nested_ai_config_widgets,
lengthof(_nested_ai_config_widgets)
753 switch (selected_slot) {
755 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
784 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
793 dim.width += padding.width;
794 dim.height += padding.height;
795 *size =
maxdim(*size, dim);
810 if (_game_mode != GM_NORMAL) {
819 return slot < max_slot;
830 text = STR_JUST_RAW_STRING;
845 text = STR_AI_CONFIG_HUMAN_PLAYER;
848 text = STR_JUST_RAW_STRING;
850 text = STR_AI_CONFIG_RANDOM_AI;
853 (this->selected_slot == i) ? TC_WHITE : (IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
864 if (this->selected_slot ==
INVALID_COMPANY || GetConfig(this->selected_slot) == NULL)
return;
879 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
898 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot - 1))) {
900 this->selected_slot--;
907 if (IsEditable(this->selected_slot) && IsEditable((
CompanyID)(this->selected_slot + 1))) {
909 this->selected_slot++;
931 #if defined(ENABLE_NETWORK) 946 if (!IsEditable(this->selected_slot)) {
950 if (!gui_scope)
return;
959 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
984 Colours colour = dead ? COLOUR_RED :
985 (paused ? COLOUR_YELLOW : COLOUR_GREY);
986 if (button.
colour != colour) {
1000 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
1008 static char break_string[MAX_BREAK_STR_STRING_LENGTH];
1015 ScriptLog::LogData *GetLogPointer()
const 1018 return (ScriptLog::LogData *)
Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
1029 return game == NULL || game->
IsDead();
1055 if (this->IsValidDebugCompany(ai_debug_company))
return;
1060 FOR_ALL_COMPANIES(c) {
1062 ChangeToAI(c->
index);
1084 if (!this->show_break_box) break_check_enabled =
false;
1086 this->last_vscroll_pos = 0;
1087 this->autoscroll =
true;
1088 this->highlight_row = -1;
1095 this->break_editbox.text.
Assign(this->break_string);
1097 this->SelectValidDebugCompany();
1105 size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
1111 this->SelectValidDebugCompany();
1130 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
1131 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
1137 if (!valid)
continue;
1139 byte offset = (i == ai_debug_company) ? 1 : 0;
1145 bool valid = game != NULL;
1146 bool dead = valid && game->
IsDead();
1147 bool paused = valid && game->
IsPaused();
1157 ScriptLog::LogData *log = this->GetLogPointer();
1159 int scroll_count = (log == NULL) ? 0 : log->used;
1160 if (this->vscroll->
GetCount() != scroll_count) {
1161 this->vscroll->
SetCount(scroll_count);
1167 if (log == NULL)
return;
1171 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
1174 if (this->autoscroll) {
1175 int scroll_pos =
max(0, log->used - this->vscroll->GetCapacity());
1184 this->last_vscroll_pos = this->vscroll->
GetPosition();
1193 assert(info != NULL);
1194 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1201 assert(info != NULL);
1202 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1216 ScriptLog::LogData *log = this->GetLogPointer();
1217 if (log == NULL)
return;
1219 int y = this->top_offset;
1220 for (
int i = this->vscroll->
GetPosition(); this->vscroll->
IsVisible(i) && i < log->used; i++) {
1221 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1222 if (log->lines[pos] == NULL)
break;
1225 switch (log->type[pos]) {
1226 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1227 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1228 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1229 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1230 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1231 default: colour = TC_BLACK;
break;
1235 if (pos == this->highlight_row) {
1237 if (colour == TC_BLACK) colour = TC_WHITE;
1254 if (!this->IsValidDebugCompany(show_ai))
return;
1256 ai_debug_company = show_ai;
1258 this->highlight_row = -1;
1265 this->autoscroll =
true;
1266 this->last_vscroll_pos = this->vscroll->
GetPosition();
1296 this->break_check_enabled = !this->break_check_enabled;
1301 this->case_sensitive_break_check = !this->case_sensitive_break_check;
1307 if (!this->IsDead()) {
1320 FOR_ALL_COMPANIES(c) {
1322 all_unpaused =
false;
1333 this->highlight_row = -1;
1343 strecpy(this->break_string, this->break_editbox.text.
buf,
lastof(this->break_string));
1358 if (!gui_scope && data == ai_debug_company && this->IsValidDebugCompany(ai_debug_company) && this->break_check_enabled && !this->break_string_filter.
IsEmpty()) {
1360 ScriptLog::LogData *log = this->GetLogPointer();
1364 this->break_string_filter.
AddLine(log->lines[log->pos]);
1365 if (this->break_string_filter.
GetState()) {
1367 if (!this->IsDead()) {
1381 this->highlight_row = log->pos;
1386 if (!gui_scope)
return;
1388 this->SelectValidDebugCompany();
1390 ScriptLog::LogData *log = ai_debug_company !=
INVALID_COMPANY ? this->GetLogPointer() : NULL;
1391 this->vscroll->
SetCount((log == NULL) ? 0 : log->used);
1446 static Hotkey aidebug_hotkeys[] = {
1503 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),
1520 WDP_AUTO,
"script_debug", 600, 450,
1523 _nested_ai_debug_widgets,
lengthof(_nested_ai_debug_widgets),
1524 &AIDebugWindow::hotkeys
1560 FOR_ALL_COMPANIES(c) {
1568 if (g != NULL && g->
IsDead()) {
EventState
State of handling an event.
GUITimer timeout
Timeout for unclicking the button.
static void Swap(T &a, T &b)
Type safe swap operation.
int GetVersion() const
Get the version of the script.
used in multiplayer to create a new companies etc.
This setting will only be visible when the Script development tools are active.
bool _networking
are we in networking mode?
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
bool autoscroll
Whether automatically scrolling should be enabled or not.
ResizeInfo resize
Resize information.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Scrollbar * vscroll
Cache of the vertical scrollbar.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
ScriptConfig * ai_config
The configuration we're modifying.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Offset at right of a matrix cell.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
static bool break_check_enabled
Stop an AI when it prints a matching string.
static void ShowAIListWindow(CompanyID slot)
Open the AI list window to chose an AI for the given company slot.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
virtual void OnPaint()
The window must be repainted.
All data for a single hotkey.
High level window description.
static void Unpause(CompanyID company)
Resume execution of the AI.
const Pair * Find(const T &key) const
Finds given key in this map.
void DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Window for configuring the AIs
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Offset at top to draw the frame rectangular area.
Scrollbar * vscroll
Cache of the vertical scrollbar.
Normal amount of vertical space between two paragraphs of text.
textfile; Window numbers:
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
bool Elapsed(uint delta)
Test if a timer has elapsed.
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
int min_value
The minimal value this configuration setting can have.
const char * GetName() const
Get the Name of the script.
bool GetState() const
Get the matching state of the current item.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static const NWidgetPart _nested_ai_settings_widgets[]
Widgets for the AI settings window.
static CompanyID ai_debug_company
The AI that is (was last) being debugged.
static const int top_offset
Offset of the text at the top of the WID_AID_LOG_PANEL.
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
CompanyID slot
The company we're selecting a new Script for.
The company is manually removed.
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
void ChangeAI()
Changes the AI of the current slot.
CompanyID slot
View the textfile of this CompanyID slot.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
void ShowNetworkContentListWindow(ContentVector *cv=NULL, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
LabelMapping * labels
Text labels for the integer values.
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
int highlight_row
The output row that matches the given string, or -1.
void InitializeAIGui()
Reset the AI windows to their initial state.
DifficultySettings difficulty
settings related to the difficulty
Tindex index
Index of this pool item.
static WindowDesc _ai_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_AI_LIST, WC_NONE, 0, _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets))
Window definition for the ai list window.
Subdirectory for all game scripts.
Offset at top of a matrix cell.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
int max_value
The maximal value this configuration setting can have.
void ShowAIConfigWindow()
Open the AI config window.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
static const int bottom_offset
Offset of the text at the bottom of the WID_AID_LOG_PANEL.
#define lastof(x)
Get the last element of an fixed size array.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
int last_vscroll_pos
Last position of the scrolling.
The AIInstance tracks an AI.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static EventState AIDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the AIDebugWindow.
void ShowAIDebugWindowIfAIError()
Open the AI debug window if one of the AI scripts has crashed.
AI debug window; Window numbers:
static T max(const T a, const T b)
Returns the maximum of two values.
void SelectValidDebugCompany()
Ensure that ai_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
All static information from an Game like name, version, etc.
int clicked_button
The button we clicked.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
void * GetLogPointer()
Get the log pointer of this script.
Window that let you choose an available AI.
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
bool _network_available
is network mode available?
T * Append(uint to_add=1)
Append an item and return it.
Force the alignment, i.e. don't swap for RTL languages.
The object is owned by a superuser / goal script.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void SetFilterTerm(const char *str)
Set the term to filter on.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Runtime information about a game script like a pointer to the squirrel vm and the current state...
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
The content consists of a game script.
bool closing_dropdown
True, if the dropdown list is currently closing.
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
CompanyID slot
The currently show company's setting.
Offset at bottom of a matrix cell.
int line_height
Height of a row in the matrix widget.
bool complete_labels
True if all values have a label.
static WindowDesc _ai_config_desc(WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
Window definition for the configure AI window.
static bool IsPaused()
Checks if the Game Script is paused.
AISettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
All static information from an Script like name, version, etc.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void OnResize()
Called after the window got resized.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Simple vector template class, with automatic delete.
Data stored about a string that can be modified in the GUI.
ClientSettings _settings_client
The current settings for this game.
int line_height
Height of a single AI-name line.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static const NWidgetPart _nested_ai_debug_widgets[]
Widgets for the AI debug window.
List of hotkeys for a window.
First company, same as owner.
AIDebugWindow(WindowDesc *desc, WindowNumber number)
Constructor for the window.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
int selected
The currently selected Script.
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Window to configure which AIs will start.
static const NWidgetPart _nested_ai_config_widgets[]
Widgets for the configure AI window.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
uint step_height
Step-size of height resize changes.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
QueryString break_editbox
Break editbox.
Offset at left of a matrix cell.
static StringFilter break_string_filter
Log filter for break.
bool clicked_dropdown
Whether the dropdown is open.
int clicked_row
The clicked row of settings.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Window for settings the parameters of an AI.
Offset at bottom to draw the frame rectangular area.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Window with everything an AI prints via ScriptLog.
static class GameInstance * GetInstance()
Get the current active instance.
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
const char * GetURL() const
Get the website for this script.
PauseModeByte _pause_mode
The current pause mode.
TextfileType
Additional text files accompanying Tar archives.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
static T min(const T a, const T b)
Returns the minimum of two values.
NWidgetBase * MakeCompanyButtonRowsAIDebug(int *biggest_index)
Make a number of rows with buttons for each company for the AI debug window.
Left offset of the text of the frame.
bool IsPaused()
Checks if the script is paused.
bool ai_developer_tools
activate AI developer tools
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static const uint8 PC_BLACK
Black palette colour.
static class GameInfo * GetInfo()
Get the current GameInfo.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
This value is a boolean (either 0 (false) or 1 (true) ).
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Maximum number of companies.
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
const char * GetDescription() const
Get the description of the script.
const char * description
The description of the configuration setting.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool IsDead() const
Return the "this script died" value.
virtual void OnResize()
Called after the window got resized.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
ScriptConfigFlags flags
Flags for the configuration setting.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static char break_string[MAX_BREAK_STR_STRING_LENGTH]
The string to match to the AI output.
AIListWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Scrollbar * vscroll
Cache of the vertical scrollbar.
char *const buf
buffer in which text is saved
const ScriptInfoList * info_list
The list of Scripts.
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
Scrollbar * vscroll
Cache of the vertical scrollbar.
GUISettings gui
settings related to the GUI
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Window for displaying a textfile.
All static information from an AI like name, version, etc.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Info about a single Script setting.
Window for displaying the textfile of a AI.
void ChangeToAI(CompanyID show_ai)
Change all settings to select another AI.
CompanyID selected_slot
The currently selected AI slot or INVALID_COMPANY.
The content consists of an AI.
VisibleSettingsList visible_settings
List of visible AI settings.
TextDirection _current_text_dir
Text direction of the currently selected language.
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
bool show_break_box
Whether the break/debug box is visible.
Subdirectory for all AI files.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the AI version of the textfile window.
static const NWidgetPart _nested_ai_list_widgets[]
Widgets for the AI list window.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
static void Unpause()
Resume execution of the Game Script.
This setting can be changed while the Script is running.
const char * GetAuthor() const
Get the Author of the script.
bool _network_server
network-server is active
Coordinates of a point in 2D.
List item containing a C char string.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
virtual void OnResize()
Called after the window got resized.
byte max_no_competitors
the number of competitors (AIs)
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
bool clicked_increase
Whether we clicked the increase or decrease button.
void ResetSettings()
Reset all settings to their default value.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
AI settings; Window numbers:
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Offset at right to draw the frame rectangular area.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
int line_height
Height of a row in the matrix widget.
Base functions for all AIs.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
int32 WindowNumber
Number to differentiate different windows of the same class.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Specification of a rectangle with absolute coordinates of all edges.
bool IsShaded() const
Is window shaded currently?
Text is written right-to-left by default.
AIConfig stores the configuration settings of every AI.
Owner
Enum for all companies/owners.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
AIInfo keeps track of all information of an AI, like Author, Description, ...
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Find a place automatically.
static bool case_sensitive_break_check
Is the matching done case-sensitive.
int step_size
The step size in the gui.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Errors (eg. saving/loading failed)
static void ShowAISettingsWindow(CompanyID slot)
Open the AI settings window to change the AI settings for an AI.
Dimensions (a width and height) of a rectangle in 2D.
Query string window; Window numbers:
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
const char * name
The name of the configuration setting.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Game options window; Window numbers:
virtual void OnPaint()
The window must be repainted.
void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
static WindowDesc _ai_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_AI_SETTINGS, WC_NONE, 0, _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets))
Window definition for the AI settings window.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
AutoDeleteSmallVector< const DropDownListItem *, 4 > DropDownList
A drop down list is a collection of drop down list items.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static WindowDesc _ai_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_AI_DEBUG, WC_NONE, 0, _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets), &AIDebugWindow::hotkeys)
Window definition for the AI debug window.