|
OpenTTD Source
14.0-beta3
|
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 "../window_func.h"
19 #include "../network/network.h"
20 #include "../widgets/dropdown_func.h"
21 #include "../hotkeys.h"
22 #include "../company_cmd.h"
23 #include "../misc_cmd.h"
24 #include "../timer/timer.h"
25 #include "../timer/timer_window.h"
27 #include "script_gui.h"
28 #include "script_log.hpp"
31 #include "../ai/ai.hpp"
32 #include "../ai/ai_config.hpp"
33 #include "../ai/ai_info.hpp"
34 #include "../ai/ai_instance.hpp"
35 #include "../game/game.hpp"
36 #include "../game/game_config.hpp"
37 #include "../game/game_info.hpp"
38 #include "../game/game_instance.hpp"
39 #include "table/strings.h"
41 #include "../safeguards.h"
80 this->vscroll->
SetCount(this->info_list->size() + 1);
84 if (GetConfig(
slot)->HasScript()) {
87 for (
const auto &item : *this->info_list) {
88 if (item.second == info) {
98 void SetStringParameters(
WidgetID widget)
const override
102 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
116 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
124 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
127 StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
129 for (
const auto &item : *this->info_list) {
134 DrawString(tr, str, (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
143 for (
const auto &item : *this->info_list) {
145 if (this->selected == i - 1) selected_info =
static_cast<ScriptInfo *
>(item.second);
148 if (selected_info !=
nullptr) {
156 if (!selected_info->
GetURL().empty()) {
174 if (this->selected == -1) {
177 ScriptInfoList::const_iterator it = this->info_list->cbegin();
178 std::advance(it, this->selected);
179 GetConfig(
slot)->
Change(it->second->GetName(), it->second->GetVersion());
187 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
192 if (sel < (
int)this->info_list->size()) {
193 this->selected = sel;
195 if (click_count > 1) {
225 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
232 if (!gui_scope)
return;
234 this->vscroll->
SetCount(this->info_list->size() + 1);
237 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
249 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_SCRL_LIST),
SetMinimalSize(188, 112),
SetFill(1, 1),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP),
SetScrollbar(
WID_SCRL_SCROLLBAR),
310 this->script_config = GetConfig(
slot);
326 visible_settings.clear();
328 for (
const auto &item : *this->script_config->
GetConfigList()) {
335 this->vscroll->
SetCount(this->visible_settings.size());
338 void SetStringParameters(
WidgetID widget)
const override
342 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
356 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
361 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
363 for (; !this->vscroll->
IsVisible(i); i++) it++;
375 int current_value = config->
GetSetting((config_item).name);
376 bool editable = this->IsEditableItem(config_item);
383 str = STR_AI_SETTINGS_JUST_DEVIATION;
385 str = STR_JUST_STRING1;
390 str = STR_AI_SETTINGS_SETTING_DEVIATION;
392 str = STR_AI_SETTINGS_SETTING;
394 colour = TC_LIGHT_BLUE;
399 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
400 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
405 DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.
min_value, editable && current_value < config_item.
max_value);
409 auto config_iterator = config_item.
labels.find(current_value);
410 if (config_iterator != config_item.
labels.end()) {
419 auto config_iterator = config_item.
labels.find(min_deviated);
420 if (config_iterator != config_item.
labels.end()) {
429 config_iterator = config_item.
labels.find(max_deviated);
430 if (config_iterator != config_item.
labels.end()) {
440 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
447 if (this->closing_dropdown) {
448 this->closing_dropdown =
false;
449 this->clicked_dropdown =
false;
454 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
459 if (it == this->visible_settings.end())
break;
462 if (!this->IsEditableItem(config_item))
return;
464 int num = it - this->visible_settings.begin();
465 if (this->clicked_row != num) {
468 this->clicked_row = num;
469 this->clicked_dropdown =
false;
475 int x = pt.x - r.left;
481 if (this->clicked_dropdown) {
484 this->clicked_dropdown =
false;
485 this->closing_dropdown =
false;
487 int rel_y = (pt.y - r.top) % this->line_height;
496 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
497 this->clicked_dropdown =
true;
498 this->closing_dropdown =
false;
502 list.push_back(std::make_unique<DropDownListStringItem>(config_item.
labels.find(i)->second, i,
false));
509 int new_val = old_val;
516 this->clicked_increase =
true;
521 this->clicked_increase =
false;
524 if (new_val != old_val) {
526 this->clicked_button = num;
549 void OnQueryTextFinished(
char *str)
override
552 int32_t value = atoi(str);
557 void OnDropdownSelect(
WidgetID widget,
int index)
override
560 assert(this->clicked_dropdown);
571 assert(this->clicked_dropdown);
572 this->closing_dropdown =
true;
583 this->clicked_button = -1;
592 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
602 return _game_mode == GM_MENU
603 || _game_mode == GM_EDITOR
609 void SetValue(
int value)
626 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_SCRS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_SCRS_SCROLLBAR),
664 this->ConstructWindow();
668 void SetStringParameters(
WidgetID widget)
const override
676 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
679 if (!textfile.has_value()) {
711 Colours colour = dead ? COLOUR_RED :
712 (paused ? COLOUR_YELLOW : COLOUR_GREY);
713 if (button.
colour != colour) {
751 ScriptLogTypes::LogData &GetLogData()
const
765 return game ==
nullptr || game->
IsDead();
813 this->filter = ScriptDebugWindow::initial_state;
821 this->last_vscroll_pos = 0;
822 this->autoscroll =
true;
823 this->highlight_row = -1;
852 ScriptDebugWindow::initial_state = this->filter;
872 void SetStringParameters(
WidgetID widget)
const override
878 assert(info !=
nullptr);
879 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
886 assert(info !=
nullptr);
887 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
893 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
930 ScriptLogTypes::LogData &log = this->GetLogData();
931 if (log.empty())
return;
939 tmp_dpi.left += fr.left;
940 tmp_dpi.top += fr.top;
946 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && (
size_t)i < log.size(); i++) {
947 const ScriptLogTypes::LogLine &line = log[i];
951 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK;
break;
952 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE;
break;
953 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK;
break;
954 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW;
break;
955 case ScriptLogTypes::LOG_ERROR: colour = TC_RED;
break;
956 default: colour = TC_BLACK;
break;
960 if (i == this->highlight_row) {
961 fr.bottom = fr.top + this->resize.step_height - 1;
963 if (colour == TC_BLACK) colour = TC_WHITE;
967 fr.top += this->resize.step_height;
979 ScriptLogTypes::LogData &log = this->GetLogData();
981 int scroll_count = (int)log.size();
982 if (this->vscroll->
GetCount() != scroll_count) {
983 this->vscroll->
SetCount(scroll_count);
989 if (log.empty())
return;
992 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
996 if (this->autoscroll && this->vscroll->
SetPosition((
int)log.size())) {
1002 this->last_vscroll_pos = this->vscroll->
GetPosition();
1030 bool valid = game !=
nullptr;
1050 ScriptDebugWindow::initial_state = this->filter;
1057 this->highlight_row = -1;
1064 this->autoscroll =
true;
1065 this->last_vscroll_pos = this->vscroll->
GetPosition();
1068 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1120 all_unpaused =
false;
1131 this->highlight_row = -1;
1137 void OnEditboxChanged(
WidgetID wid)
override
1152 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1159 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1160 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1162 ScriptLogTypes::LogData &log = this->GetLogData();
1166 this->break_string_filter.
AddLine(log.back().text);
1167 if (this->break_string_filter.
GetState()) {
1183 this->highlight_row = (int)(log.size() - 1);
1188 if (!gui_scope)
return;
1194 for (
auto &line : this->GetLogData()) {
1196 max_width = std::max(max_width, line.width);
1213 this->filter.script_debug_company ==
OWNER_DEITY ||
1238 static inline HotkeyList hotkeys{
"aidebug", {
1302 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SCRD_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),
1320 WDP_AUTO,
"script_debug", 600, 450,
1324 &ScriptDebugWindow::hotkeys
1378 if (c->is_ai && c->ai_instance->IsDead()) {
1385 if (g !=
nullptr && g->
IsDead()) {
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
std::string break_string
The string to match to the AI output.
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
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-...
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
@ WC_SCRIPT_DEBUG
Script debug window; Window numbers:
static bool IsPaused()
Checks if the Game Script is paused.
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
bool autoscroll
Whether automatically scrolling should be enabled or not.
static class GameInstance * GetGameInstance()
Get the current GameScript instance.
static Titem * Get(size_t index)
Returns Titem with given index.
List of hotkeys for a window.
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
const ScriptInfoList * info_list
The list of Scripts.
Dimensions (a width and height) of a rectangle in 2D.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int step_size
The step size in the gui.
void SelectValidDebugCompany()
Ensure that script_debug_company refers to a valid AI company or GS, or is set to INVALID_COMPANY.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
void SetFilterTerm(const char *str)
Set the term to filter on.
std::string name
The name of the configuration setting.
Window that let you choose an available Script.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
int line_height
Height of a row in the matrix widget.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
bool _network_server
network-server is active
void Assign(StringID string)
Render a string into the textbuffer.
bool break_check_enabled
Stop an AI when it prints a matching string.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
static class GameInfo * GetInfo()
Get the current GameInfo.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Scrollbar * vscroll
Cache of the vertical scrollbar.
static constexpr NWidgetPart _nested_script_settings_widgets[]
Widgets for the Script settings window.
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void OnPaint() override
The window must be repainted.
void UpdateGSButtonState()
Update state of game script button.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
static constexpr NWidgetPart _nested_script_debug_widgets[]
Widgets for the Script debug window.
int last_vscroll_pos
Last position of the scrolling.
bool _ctrl_pressed
Is Ctrl pressed?
Scrollbar * vscroll
Cache of the vertical scrollbar.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
CompanyID slot
The company we're selecting a new Script for.
ScriptLogTypes::LogData & GetLogData()
Get the log pointer of this script.
ClientSettings _settings_client
The current settings for this game.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
static void Unpause()
Resume execution of the Game Script.
static constexpr NWidgetPart _nested_script_list_widgets[]
Widgets for the AI list window.
ScriptDebugWindow(WindowDesc *desc, WindowNumber number, Owner show_company)
Constructor for the window.
void InitializeScriptGui()
Reset the Script windows to their initial state.
Owner
Enum for all companies/owners.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
int redraw_timer
Timer for redrawing the window, otherwise it'll happen every tick.
TextfileType file_type
Type of textfile to view.
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.
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
Draw a company button icon.
Data stored about a string that can be modified in the GUI.
int highlight_row
The output row that matches the given string, or -1.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
int min_value
The minimal value this configuration setting can have.
char *const buf
buffer in which text is saved
void OnResize() override
Called after the window got resized.
const std::string & GetAuthor() const
Get the Author of the script.
@ PM_UNPAUSED
A normal unpaused game.
bool show_break_box
Whether the break/debug box is visible.
High level window description.
void Reset()
Reset the timer, so it will fire again after the timeout.
ScriptListWindow(WindowDesc *desc, CompanyID slot, bool show_all)
Constructor for the window.
bool complete_labels
True if all values have a label.
@ COMPANY_FIRST
First company, same as owner.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
static void Unpause(CompanyID company)
Resume execution of the AI.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
void OnInit() override
Notification that the nested widget tree gets initialized.
int line_height
Height of a row in the matrix widget.
@ WC_QUERY_STRING
Query string window; Window numbers:
bool ai_developer_tools
activate AI/GS developer tools
int max_value
The maximal value this configuration setting can have.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ FS_NORMAL
Index of the normal font in the font tables.
bool clicked_dropdown
Whether the dropdown is open.
const std::string & GetURL() const
Get the website for this script.
@ AI_DIR
Subdirectory for all AI files.
@ CCA_NEW_AI
Create a new AI company.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
@ ES_NOT_HANDLED
The passed event is not handled.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
bool IsDead() const
Return the "this script died" value.
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
PauseMode _pause_mode
The current pause mode.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
static WindowDesc _script_settings_desc(__FILE__, __LINE__, WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, 0, std::begin(_nested_script_settings_widgets), std::end(_nested_script_settings_widgets))
Window definition for the Script settings window.
@ 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.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
bool show_all
Whether to show all available versions.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
const std::string & GetName() const
Get the Name of the script.
int clicked_row
The clicked row of settings.
void OnPaint() override
The window must be repainted.
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 ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
@ GAME_DIR
Subdirectory for all game scripts.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Scrollbar * hscroll
Cache of the horizontal scrollbar.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
VisibleSettingsList visible_settings
List of visible AI settings.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
Coordinates of a point in 2D.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Window for displaying the textfile of a AI.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
WindowNumber window_number
Window number within the window class.
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 InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Iterable ensemble of all valid Windows.
const std::string & GetDescription() const
Get the description of the script.
static WindowDesc _script_list_desc(__FILE__, __LINE__, WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, 0, std::begin(_nested_script_list_widgets), std::end(_nested_script_list_widgets))
Window definition for the ai list window.
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Runtime information about a game script like a pointer to the squirrel vm and the current state.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
CompanyID slot
The currently show company's setting.
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
StringFilter break_string_filter
Log filter for break.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void ChangeScript()
Changes the Script of the current slot.
Window with everything an AI prints via ScriptLog.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
int GetVersion() const
Get the version of the script.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
void UpdateAIButtonsState()
Update state of all Company (AI) buttons.
@ CRR_NONE
Dummy reason for actions that don't need one.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
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...
Scrollbar * vscroll
Cache of the vertical scrollbar.
void ResetState()
Reset the matching state to process a new item.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
@ PM_PAUSED_NORMAL
A game normally paused.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
CompanyID script_debug_company
The AI that is (was last) being debugged.
EventState
State of handling an event.
All static information from an Game like name, version, etc.
@ WN_GAME_OPTIONS_GS
GS settings.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
bool GetState() const
Get the matching state of the current item.
WindowClass window_class
Window class.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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.
@ INVALID_CLIENT_ID
Client is not part of anything.
static const uint8_t PC_BLACK
Black palette colour.
int selected
The currently selected Script.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
@ WN_GAME_OPTIONS_AI
AI settings.
@ SA_LEFT
Left align the text.
bool case_sensitive_break_check
Is the matching done case-sensitive.
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
static WindowDesc _script_debug_desc(__FILE__, __LINE__, WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, 0, std::begin(_nested_script_debug_widgets), std::end(_nested_script_debug_widgets), &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
Window for settings the parameters of an AI.
All static information from an AI like name, version, etc.
std::string description
The description of the configuration setting.
ScriptConfigFlags flags
Flags for the configuration setting.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
@ INVALID_COMPANY
An invalid company.
bool IsPaused()
Checks if the script is paused.
Window for displaying a textfile.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
ScriptSettingsWindow(WindowDesc *desc, CompanyID slot)
Constructor for the window.
bool clicked_increase
Whether we clicked the increase or decrease button.
Data structure for an opened window.
TextfileType
Additional text files accompanying Tar archives.
int clicked_button
The button we clicked.
bool closing_dropdown
True, if the dropdown list is currently closing.
QueryString break_editbox
Break editbox.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
LabelMapping labels
Text labels for the integer values.
void ChangeToScript(CompanyID show_script, bool new_window=false)
Change all settings to select another Script.
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
void DrawWidgets() const
Paint all widgets of a window.
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
int Width() const
Get width of Rect.
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
@ CCA_DELETE
Delete a company.
All static information from an Script like name, version, etc.
ScriptConfig * script_config
The configuration we're modifying.
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
static class GameInstance * GetInstance()
Get the current active instance.
Specification of a rectangle with absolute coordinates of all edges.
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Info about a single Script setting.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
int random_deviation
The maximum random deviation from the default value.
@ WC_TEXTFILE
textfile; Window numbers:
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
@ WDP_CENTER
Center the window.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
void OnResize() override
Called after the window got resized.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void DrawWidgetLog(const Rect &r) const
Draw the AI/GS log.
@ CRR_MANUAL
The company is manually removed.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
void OnResize() override
Called after the window got resized.
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 ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close)
Show a drop down list.
static const ScriptInfoList * GetInfoList()
Wrapper function for GameScanner::GetInfoList.
Data about how and where to blit pixels.
All data for a single hotkey.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.