OpenTTD Source  20240919-master-gdf0233f4c2
script_gui.cpp File Reference
#include "../stdafx.h"
#include "../table/sprites.h"
#include "../error.h"
#include "../settings_gui.h"
#include "../querystring_gui.h"
#include "../stringfilter_type.h"
#include "../company_base.h"
#include "../company_gui.h"
#include "../dropdown_type.h"
#include "../dropdown_func.h"
#include "../window_func.h"
#include "../network/network.h"
#include "../hotkeys.h"
#include "../company_cmd.h"
#include "../misc_cmd.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "script_gui.h"
#include "script_log.hpp"
#include "script_scanner.hpp"
#include "script_config.hpp"
#include "../ai/ai.hpp"
#include "../ai/ai_config.hpp"
#include "../ai/ai_info.hpp"
#include "../ai/ai_instance.hpp"
#include "../game/game.hpp"
#include "../game/game_config.hpp"
#include "../game/game_info.hpp"
#include "../game/game_instance.hpp"
#include "table/strings.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  ScriptListWindow
 Window that let you choose an available Script. More...
 
struct  ScriptSettingsWindow
 Window for settings the parameters of an AI. More...
 
struct  ScriptTextfileWindow
 Window for displaying the textfile of a AI. More...
 
struct  ScriptDebugWindow
 Window with everything an AI prints via ScriptLog. More...
 
struct  ScriptDebugWindow::FilterState
 

Functions

static ScriptConfigGetConfig (CompanyID slot)
 
void ShowScriptListWindow (CompanyID slot, bool show_all)
 Open the Script list window to chose a script for the given company slot. More...
 
void ShowScriptSettingsWindow (CompanyID slot)
 Open the Script settings window to change the Script settings for a Script. More...
 
void ShowScriptTextfileWindow (TextfileType file_type, CompanyID slot)
 Open the Script version of the textfile window. More...
 
static bool SetScriptButtonColour (NWidgetCore &button, bool dead, bool paused)
 Set the widget colour of a button based on the state of the script. More...
 
std::unique_ptr< NWidgetBaseMakeCompanyButtonRowsScriptDebug ()
 Make a number of rows with buttons for each company for the Script debug window.
 
WindowShowScriptDebugWindow (CompanyID show_company, bool new_window)
 Open the Script debug window and select the given company. More...
 
void InitializeScriptGui ()
 Reset the Script windows to their initial state.
 
void ShowScriptDebugWindowIfScriptError ()
 Open the AI debug window if one of the AI scripts has crashed.
 

Variables

static constexpr NWidgetPart _nested_script_list_widgets []
 Widgets for the AI list window. More...
 
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.
 
static constexpr NWidgetPart _nested_script_settings_widgets []
 Widgets for the Script settings window. More...
 
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.
 
static constexpr NWidgetPart _nested_script_debug_widgets []
 Widgets for the Script debug window.
 
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.
 

Detailed Description

Window for configuring the Scripts

Definition in file script_gui.cpp.

Function Documentation

◆ SetScriptButtonColour()

static bool SetScriptButtonColour ( NWidgetCore button,
bool  dead,
bool  paused 
)
static

Set the widget colour of a button based on the state of the script.

(dead or alive)

Parameters
buttonthe button to update.
deadtrue if the script is dead, otherwise false.
pausedtrue if the script is paused, otherwise false.
Returns
true if the colour was changed and the window need to be marked as dirty.

Definition at line 676 of file script_gui.cpp.

Referenced by ScriptDebugWindow::UpdateAIButtonsState(), and ScriptDebugWindow::UpdateGSButtonState().

◆ ShowScriptDebugWindow()

Window* ShowScriptDebugWindow ( CompanyID  show_company,
bool  new_window 
)

Open the Script debug window and select the given company.

Parameters
show_companyDisplay debug information about this AI company.
new_windowShow in new window instead of existing window.

Definition at line 1303 of file script_gui.cpp.

References _network_server, _networking, _script_debug_desc, BringWindowToFrontById(), ScriptDebugWindow::ChangeToScript(), FindWindowByClass(), FindWindowById(), INVALID_STRING_ID, ScriptDebugWindow::FilterState::script_debug_company, ShowErrorMessage(), WC_SCRIPT_DEBUG, Window::window_class, Window::window_number, and WL_INFO.

Referenced by ScriptDebugWindow::ChangeToScript(), and ShowScriptDebugWindowIfScriptError().

◆ ShowScriptListWindow()

void ShowScriptListWindow ( CompanyID  slot,
bool  show_all 
)

Open the Script list window to chose a script for the given company slot.

Parameters
slotThe slot to change the script of.
show_allWhether to show all available versions.

Definition at line 277 of file script_gui.cpp.

References _script_list_desc, CloseWindowByClass(), and WC_SCRIPT_LIST.

◆ ShowScriptSettingsWindow()

void ShowScriptSettingsWindow ( CompanyID  slot)

Open the Script settings window to change the Script settings for a Script.

Parameters
slotThe CompanyID of the Script to change the settings.

Definition at line 619 of file script_gui.cpp.

References _script_settings_desc, CloseWindowByClass(), WC_SCRIPT_LIST, and WC_SCRIPT_SETTINGS.

◆ ShowScriptTextfileWindow()

void ShowScriptTextfileWindow ( TextfileType  file_type,
CompanyID  slot 
)

Open the Script version of the textfile window.

Parameters
file_typeThe type of textfile to display.
slotThe slot the Script is using.

Definition at line 661 of file script_gui.cpp.

References CloseWindowById(), and WC_TEXTFILE.

Variable Documentation

◆ _nested_script_list_widgets

constexpr NWidgetPart _nested_script_list_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
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),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
}

Widgets for the AI list window.

Definition at line 243 of file script_gui.cpp.

◆ _nested_script_settings_widgets

constexpr NWidgetPart _nested_script_settings_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
}

Widgets for the Script settings window.

Definition at line 588 of file script_gui.cpp.

SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1183
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1216
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:526
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1128
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1286
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:114
WID_SCRL_SCROLLBAR
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
Definition: script_widget.h:19
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
WID_SCRS_ACCEPT
@ WID_SCRS_ACCEPT
Accept button.
Definition: script_widget.h:30
WID_SCRL_INFO_BG
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
Definition: script_widget.h:20
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
WID_SCRS_CAPTION
@ WID_SCRS_CAPTION
Caption of the window.
Definition: script_widget.h:27
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WID_SCRL_ACCEPT
@ WID_SCRL_ACCEPT
Accept button.
Definition: script_widget.h:21
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WID_SCRL_CANCEL
@ WID_SCRL_CANCEL
Cancel button.
Definition: script_widget.h:22
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
WID_SCRS_RESET
@ WID_SCRS_RESET
Reset button.
Definition: script_widget.h:31
WID_SCRL_CAPTION
@ WID_SCRL_CAPTION
Caption of the window.
Definition: script_widget.h:17
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1139
WID_SCRS_BACKGROUND
@ WID_SCRS_BACKGROUND
Panel to draw the settings on.
Definition: script_widget.h:28
WID_SCRL_LIST
@ WID_SCRL_LIST
The matrix with all available Scripts.
Definition: script_widget.h:18
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1204
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1151
WID_SCRS_SCROLLBAR
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: script_widget.h:29