OpenTTD Source: src/script/script_gui.cpp File Reference

OpenTTD Source 14.0-beta3

Data Structures | Functions | Variables
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 "../window_func.h"`
`#include "../network/network.h"`
`#include "../widgets/dropdown_func.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 ScriptConfig * | GetConfig (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< NWidgetBase > | MakeCompanyButtonRowsScriptDebug ()
| Make a number of rows with buttons for each company for the Script debug window.
Window * | ShowScriptDebugWindow (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 (__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.
static constexpr NWidgetPart | _nested_script_settings_widgets []
| Widgets for the Script settings window. More...
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.
static constexpr NWidgetPart | _nested_script_debug_widgets []
| Widgets for the Script debug window.
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.

## 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

  button | the button to update.
  dead | true if the script is dead, otherwise false.
  paused | true 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 707 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_company | Display debug information about this AI company.
  new_window | Show in new window instead of existing window.

Definition at line 1332 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(), GameInstance::Died(), 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

  slot | The slot to change the script of.
  show_all | Whether to show all available versions.

Definition at line 276 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

  slot | The CompanyID of the Script to change the settings.

Definition at line 650 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_type | The type of textfile to display.
  slot | The slot the Script is using.

Definition at line 692 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(NWID_HORIZONTAL),
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),
EndContainer(),
NWidget(NWID_HORIZONTAL),
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(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRL_SCROLLBAR),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_MAUVE, WID_SCRL_INFO_BG), SetMinimalTextLines(8, WidgetDimensions::unscaled.framerect.Vertical() + WidgetDimensions::unscaled.vsep_normal * 3), SetResize(1, 0),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
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),
EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
EndContainer(),
}

Widgets for the AI list window.

Definition at line 242 of file script_gui.cpp.

## ◆ _nested_script_settings_widgets

constexpr NWidgetPart _nested_script_settings_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
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),
EndContainer(),
NWidget(NWID_HORIZONTAL),
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),
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRS_SCROLLBAR),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
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),
EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
EndContainer(),
}

Widgets for the Script settings window.

Definition at line 619 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:1141
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:1151
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:1174
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
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:1258
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:1097
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:1162
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:1109
WID_SCRS_SCROLLBAR
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: script_widget.h:29