OpenTTD Source
20240917-master-g9ab0a47812
|
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 "../dropdown_type.h"
19 #include "../dropdown_func.h"
20 #include "../window_func.h"
21 #include "../network/network.h"
22 #include "../hotkeys.h"
23 #include "../company_cmd.h"
24 #include "../misc_cmd.h"
25 #include "../timer/timer.h"
26 #include "../timer/timer_window.h"
28 #include "script_gui.h"
29 #include "script_log.hpp"
32 #include "../ai/ai.hpp"
33 #include "../ai/ai_config.hpp"
34 #include "../ai/ai_info.hpp"
35 #include "../ai/ai_instance.hpp"
36 #include "../game/game.hpp"
37 #include "../game/game_config.hpp"
38 #include "../game/game_info.hpp"
39 #include "../game/game_instance.hpp"
40 #include "table/strings.h"
42 #include "../safeguards.h"
81 this->vscroll->
SetCount(this->info_list->size() + 1);
85 if (GetConfig(
slot)->HasScript()) {
88 for (
const auto &item : *this->info_list) {
89 if (item.second == info) {
99 void SetStringParameters(
WidgetID widget)
const override
103 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
117 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
125 DrawString(tr, this->slot ==
OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
128 StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
130 for (
const auto &item : *this->info_list) {
135 DrawString(tr, str, (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
144 for (
const auto &item : *this->info_list) {
146 if (this->selected == i - 1) selected_info =
static_cast<ScriptInfo *
>(item.second);
149 if (selected_info !=
nullptr) {
157 if (!selected_info->
GetURL().empty()) {
175 if (this->selected == -1) {
178 ScriptInfoList::const_iterator it = this->info_list->cbegin();
179 std::advance(it, this->selected);
180 GetConfig(
slot)->
Change(it->second->GetName(), it->second->GetVersion());
188 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
193 if (sel < (
int)this->info_list->size()) {
194 this->selected = sel;
196 if (click_count > 1) {
226 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
233 if (!gui_scope)
return;
235 this->vscroll->
SetCount(this->info_list->size() + 1);
238 this->selected = std::min(this->selected, this->vscroll->
GetCount() - 2);
250 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),
325 visible_settings.clear();
327 for (
const auto &item : *this->script_config->
GetConfigList()) {
334 this->vscroll->
SetCount(this->visible_settings.size());
337 void SetStringParameters(
WidgetID widget)
const override
341 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
355 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
369 for (
auto it = first; it != last; ++it) {
371 int current_value = this->script_config->
GetSetting(config_item.
name);
372 bool editable = this->IsEditableItem(config_item);
378 str = STR_JUST_STRING1;
381 str = STR_AI_SETTINGS_SETTING;
382 colour = TC_LIGHT_BLUE;
387 DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
388 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
390 int i =
static_cast<int>(std::distance(std::begin(this->visible_settings), it));
394 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);
397 auto config_iterator = config_item.
labels.find(current_value);
398 if (config_iterator != config_item.
labels.end()) {
407 DrawString(tr.left, tr.right, y + text_y_offset, str, colour);
414 if (this->closing_dropdown) {
415 this->closing_dropdown =
false;
416 this->clicked_dropdown =
false;
421 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
426 if (it == this->visible_settings.end())
break;
429 if (!this->IsEditableItem(config_item))
return;
431 int num = it - this->visible_settings.begin();
432 if (this->clicked_row != num) {
435 this->clicked_row = num;
436 this->clicked_dropdown =
false;
442 int x = pt.x - r.left;
448 if (this->clicked_dropdown) {
451 this->clicked_dropdown =
false;
452 this->closing_dropdown =
false;
454 int rel_y = (pt.y - r.top) % this->line_height;
463 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
464 this->clicked_dropdown =
true;
465 this->closing_dropdown =
false;
469 list.push_back(MakeDropDownListStringItem(config_item.
labels.find(i)->second, i));
476 int new_val = old_val;
483 this->clicked_increase =
true;
488 this->clicked_increase =
false;
491 if (new_val != old_val) {
493 this->clicked_button = num;
516 void OnQueryTextFinished(std::optional<std::string> str)
override
518 if (!str.has_value() || str->empty())
return;
519 int32_t value = atoi(str->c_str());
524 void OnDropdownSelect(
WidgetID widget,
int index)
override
527 assert(this->clicked_dropdown);
538 assert(this->clicked_dropdown);
539 this->closing_dropdown =
true;
550 this->clicked_button = -1;
559 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
561 this->script_config = GetConfig(this->slot);
571 return _game_mode == GM_MENU
572 || _game_mode == GM_EDITOR
578 void SetValue(
int value)
595 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),
633 this->ConstructWindow();
637 void SetStringParameters(
WidgetID widget)
const override
645 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
648 if (!textfile.has_value()) {
680 Colours colour = dead ? COLOUR_RED :
681 (paused ? COLOUR_YELLOW : COLOUR_GREY);
682 if (button.
colour != colour) {
720 ScriptLogTypes::LogData &GetLogData()
const
734 return game ==
nullptr || game->
IsDead();
782 this->filter = ScriptDebugWindow::initial_state;
790 this->last_vscroll_pos = 0;
791 this->autoscroll =
true;
792 this->highlight_row = -1;
821 ScriptDebugWindow::initial_state = this->filter;
841 void SetStringParameters(
WidgetID widget)
const override
847 assert(info !=
nullptr);
848 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
855 assert(info !=
nullptr);
856 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
862 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
899 const ScriptLogTypes::LogData &log = this->GetLogData();
900 if (log.empty())
return;
908 tmp_dpi.left += fr.left;
909 tmp_dpi.top += fr.top;
916 for (
auto it = first; it != last; ++it) {
917 const ScriptLogTypes::LogLine &line = *it;
921 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK;
break;
922 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE;
break;
923 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK;
break;
924 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW;
break;
925 case ScriptLogTypes::LOG_ERROR: colour = TC_RED;
break;
926 default: colour = TC_BLACK;
break;
930 if (std::distance(std::begin(log), it) == this->highlight_row) {
931 fr.bottom = fr.top + this->resize.step_height - 1;
933 if (colour == TC_BLACK) colour = TC_WHITE;
937 fr.top += this->resize.step_height;
949 ScriptLogTypes::LogData &log = this->GetLogData();
951 int scroll_count = (int)log.size();
952 if (this->vscroll->
GetCount() != scroll_count) {
953 this->vscroll->
SetCount(scroll_count);
959 if (log.empty())
return;
962 if (this->last_vscroll_pos != this->vscroll->
GetPosition()) {
966 if (this->autoscroll && this->vscroll->
SetPosition((
int)log.size())) {
972 this->last_vscroll_pos = this->vscroll->
GetPosition();
1000 bool valid = game !=
nullptr;
1020 ScriptDebugWindow::initial_state = this->filter;
1027 this->highlight_row = -1;
1034 this->autoscroll =
true;
1035 this->last_vscroll_pos = this->vscroll->
GetPosition();
1038 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1090 all_unpaused =
false;
1101 this->highlight_row = -1;
1107 void OnEditboxChanged(
WidgetID wid)
override
1122 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1129 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1130 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1132 ScriptLogTypes::LogData &log = this->GetLogData();
1136 this->break_string_filter.
AddLine(log.back().text);
1137 if (this->break_string_filter.
GetState()) {
1153 this->highlight_row = (int)(log.size() - 1);
1158 if (!gui_scope)
return;
1164 for (
auto &line : this->GetLogData()) {
1166 max_width = std::max(max_width, line.width);
1184 this->filter.script_debug_company ==
OWNER_DEITY ||
1209 static inline HotkeyList hotkeys{
"aidebug", {
1273 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),
1291 WDP_AUTO,
"script_debug", 600, 450,
1295 &ScriptDebugWindow::hotkeys
1349 if (c->is_ai && c->ai_instance->IsDead()) {
1356 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.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
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.
static WindowDesc _script_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, 0, _nested_script_debug_widgets, &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
@ 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.
static WindowDesc _script_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, 0, _nested_script_settings_widgets)
Window definition for the Script settings window.
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.
@ INVALID_COMPANY
An invalid company.
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.
Owner
Enum for all companies/owners.
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).
ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all)
Constructor for the window.
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.
ScriptSettingsWindow(WindowDesc &desc, CompanyID slot)
Constructor for the window.
void InitializeScriptGui()
Reset the Script windows to their initial state.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
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.
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
bool show_break_box
Whether the break/debug box is visible.
High level window description.
static WindowDesc _script_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, 0, _nested_script_list_widgets)
Window definition for the ai list window.
void Reset()
Reset the timer, so it will fire again after the timeout.
bool complete_labels
True if all values have a label.
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:
@ COMPANY_FIRST
First company, same as owner.
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.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
Show a drop down list.
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.
@ 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.
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.
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.
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.
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.
ScriptDebugWindow(WindowDesc &desc, WindowNumber number, Owner show_company)
Constructor for the window.
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.
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.
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.
bool IsPaused()
Checks if the script is paused.
Window for displaying a textfile.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
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.
@ MAX_COMPANIES
Maximum number of companies.
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.
@ PM_UNPAUSED
A normal unpaused game.
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.
@ PM_PAUSED_NORMAL
A game normally paused.
@ 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
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.