OpenTTD Source 20241224-master-gf74b0cf984
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.
 
void ShowScriptSettingsWindow (CompanyID slot)
 Open the Script settings window to change the Script settings for a Script.
 
void ShowScriptTextfileWindow (TextfileType file_type, CompanyID slot)
 Open the Script version of the textfile window.
 
static bool SetScriptButtonColour (NWidgetCore &button, bool dead, bool paused)
 Set the widget colour of a button based on the state of the script.
 
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.
 
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.
 
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.
 
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

◆ GetConfig()

static ScriptConfig * GetConfig ( CompanyID  slot)
static

Definition at line 45 of file script_gui.cpp.

◆ InitializeScriptGui()

void InitializeScriptGui ( )

Reset the Script windows to their initial state.

Definition at line 1337 of file script_gui.cpp.

References INVALID_COMPANY, and ScriptDebugWindow::FilterState::script_debug_company.

◆ MakeCompanyButtonRowsScriptDebug()

std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug ( )

Make a number of rows with buttons for each company for the Script debug window.

Definition at line 1236 of file script_gui.cpp.

References MakeCompanyButtonRows(), WID_SCRD_COMPANY_BUTTON_END, and WID_SCRD_COMPANY_BUTTON_START.

◆ 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.

References NWidgetCore::colour.

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

◆ ShowScriptDebugWindow()

Window * ShowScriptDebugWindow ( CompanyID  show_company,
bool  new_window 
)

◆ ShowScriptDebugWindowIfScriptError()

void 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.

Referenced by AIConfigWindow::OnClick(), and GSConfigWindow::OnClick().

◆ 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.

Referenced by AIConfigWindow::OnClick(), and ScriptDebugWindow::OnClick().

◆ 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.

Referenced by AIConfigWindow::OnClick(), and GSConfigWindow::OnClick().

Variable Documentation

◆ _nested_script_debug_widgets

constexpr NWidgetPart _nested_script_debug_widgets[]
staticconstexpr

Widgets for the Script debug window.

Definition at line 1242 of file script_gui.cpp.

◆ _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:96
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
@ WID_SCRL_ACCEPT
Accept button.
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
@ WID_SCRL_CAPTION
Caption of the window.
@ WID_SCRL_LIST
The matrix with all available Scripts.
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
@ WID_SCRL_CANCEL
Cancel button.
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ 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:85
@ 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.
@ WID_SCRS_ACCEPT
Accept button.
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
@ WID_SCRS_RESET
Reset button.
@ WID_SCRS_CAPTION
Caption of the window.

Widgets for the Script settings window.

Definition at line 588 of file script_gui.cpp.