OpenTTD Source  20241109-master-g5e4f8db7d6
script_gui.cpp File Reference

Window for configuring the Scripts More...

#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),
}
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1181
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1284
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
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:1214
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
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:1149
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
@ WID_SCRL_ACCEPT
Accept button.
Definition: script_widget.h:21
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
Definition: script_widget.h:20
@ WID_SCRL_CAPTION
Caption of the window.
Definition: script_widget.h:17
@ WID_SCRL_LIST
The matrix with all available Scripts.
Definition: script_widget.h:18
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
Definition: script_widget.h:19
@ WID_SCRL_CANCEL
Cancel button.
Definition: script_widget.h:22
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:524
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:112
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:59
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:65

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),
}
@ WID_SCRS_BACKGROUND
Panel to draw the settings on.
Definition: script_widget.h:28
@ WID_SCRS_ACCEPT
Accept button.
Definition: script_widget.h:30
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: script_widget.h:29
@ WID_SCRS_RESET
Reset button.
Definition: script_widget.h:31
@ WID_SCRS_CAPTION
Caption of the window.
Definition: script_widget.h:27

Widgets for the Script settings window.

Definition at line 588 of file script_gui.cpp.