OpenTTD Source 20250205-master-gfd85ab1e2c
newgrf_gui.cpp File Reference

GUI to change NewGRF settings. More...

#include "stdafx.h"
#include "error.h"
#include "settings_gui.h"
#include "newgrf.h"
#include "strings_func.h"
#include "window_func.h"
#include "gamelog.h"
#include "settings_type.h"
#include "settings_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "network/network.h"
#include "network/network_content.h"
#include "sortlist_type.h"
#include "stringfilter_type.h"
#include "querystring_gui.h"
#include "core/geometry_func.hpp"
#include "newgrf_text.h"
#include "textfile_gui.h"
#include "tilehighlight_func.h"
#include "fios.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "zoom_func.h"
#include "widgets/newgrf_widget.h"
#include "widgets/misc_widget.h"
#include "table/sprites.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  NewGRFParametersWindow
 Window for setting the parameters of a NewGRF. More...
 
struct  NewGRFTextfileWindow
 Window for displaying the textfile of a NewGRF. More...
 
struct  NewGRFWindow
 Window for showing NewGRF files. More...
 
class  NWidgetNewGRFDisplay
 Custom nested widget container for the NewGRF gui. More...
 
struct  SavePresetWindow
 Class for the save preset window. More...
 
struct  ScanProgressWindow
 Window for showing the progress of NewGRF scanning. More...
 

Typedefs

typedef std::map< uint32_t, const GRFConfig * > GrfIdMap
 Map of grfid to the grf config.
 

Functions

void ShowNewGRFError ()
 Show the first NewGRF error we can find.
 
static void ShowNewGRFInfo (const GRFConfig &c, const Rect &r, bool show_params)
 
void OpenGRFParameterWindow (bool is_baseset, GRFConfig &c, bool editable)
 
void ShowNewGRFTextfileWindow (TextfileType file_type, const GRFConfig *c)
 
static void FillGrfidMap (const GRFConfigList &lst, GrfIdMap &grfid_map)
 Add all grf configs from c into the map.
 
static void NewGRFConfirmationCallback (Window *w, bool confirmed)
 Callback function for the newgrf 'apply changes' confirmation window.
 
static void ShowSavePresetWindow (const char *initial_text)
 Open the window for saving a preset.
 
void ShowMissingContentWindow (const GRFConfigList &list)
 Show the content list window with all missing grfs from the given list.
 
std::unique_ptr< NWidgetBaseNewGRFDisplay ()
 Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.
 
void ShowNewGRFSettings (bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
 Setup the NewGRF gui.
 
void UpdateNewGRFScanStatus (uint num, const char *name)
 Update the NewGRF scan status.
 

Variables

static constexpr NWidgetPart _nested_newgrf_parameter_widgets []
 
static WindowDesc _newgrf_parameters_desc (WDP_CENTER, "settings_newgrf_config", 500, 208, WC_GRF_PARAMETERS, WC_NONE, {}, _nested_newgrf_parameter_widgets)
 Window definition for the change grf parameters window.
 
static constexpr NWidgetPart _nested_newgrf_actives_widgets []
 
static constexpr NWidgetPart _nested_newgrf_availables_widgets []
 
static constexpr NWidgetPart _nested_newgrf_infopanel_widgets []
 
static constexpr NWidgetPart _nested_newgrf_widgets []
 
static WindowDesc _newgrf_desc (WDP_CENTER, "settings_newgrf", 300, 263, WC_GAME_OPTIONS, WC_NONE, {}, _nested_newgrf_widgets)
 
static constexpr NWidgetPart _nested_save_preset_widgets []
 Widget parts of the save preset window.
 
static WindowDesc _save_preset_desc (WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WindowDefaultFlag::Modal, _nested_save_preset_widgets)
 Window description of the preset save window.
 
static constexpr NWidgetPart _nested_scan_progress_widgets []
 Widgets for the progress window.
 
static WindowDesc _scan_progress_desc (WDP_CENTER, nullptr, 0, 0, WC_MODAL_PROGRESS, WC_NONE, {}, _nested_scan_progress_widgets)
 Description of the widgets and other settings of the window.
 

Detailed Description

GUI to change NewGRF settings.

Definition in file newgrf_gui.cpp.

Typedef Documentation

◆ GrfIdMap

typedef std::map<uint32_t, const GRFConfig *> GrfIdMap

Map of grfid to the grf config.

Definition at line 581 of file newgrf_gui.cpp.

Function Documentation

◆ FillGrfidMap()

static void FillGrfidMap ( const GRFConfigList &  lst,
GrfIdMap grfid_map 
)
static

Add all grf configs from c into the map.

Parameters
lstGrf list to add.
grfid_mapMap to add them to.

Definition at line 588 of file newgrf_gui.cpp.

References GRFIdentifier::grfid, and GRFConfig::ident.

Referenced by NewGRFWindow::CanUpgradeCurrent(), and NewGRFWindow::UpgradeCurrent().

◆ NewGRFConfirmationCallback()

static void NewGRFConfirmationCallback ( Window w,
bool  confirmed 
)
static

Callback function for the newgrf 'apply changes' confirmation window.

Parameters
wWindow which is calling this callback
confirmedboolean value, true when yes was clicked, false otherwise

Definition at line 1938 of file newgrf_gui.cpp.

References _gamelog, _grfconfig, NewGRFWindow::active_sel, NewGRFWindow::actives, NewGRFWindow::avails, CloseWindowByClass(), CopyGRFConfigList(), GUIList< T, P, F >::ForceRebuild(), GLAT_GRF, Gamelog::GRFUpdate(), Window::InvalidateData(), NewGRFWindow::modified, NewGRFWindow::orig_list, ReInitAllWindows(), ReloadNewGRFData(), Gamelog::StartAction(), Gamelog::StopAction(), WC_BUILD_OBJECT, WC_GRF_PARAMETERS, and WC_TEXTFILE.

Referenced by NewGRFWindow::OnClick().

◆ NewGRFDisplay()

std::unique_ptr< NWidgetBase > NewGRFDisplay ( )

Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.

Definition at line 1899 of file newgrf_gui.cpp.

References MakeNWidgets().

◆ OpenGRFParameterWindow()

void OpenGRFParameterWindow ( bool  is_baseset,
GRFConfig c,
bool  editable 
)

Definition at line 548 of file newgrf_gui.cpp.

◆ ShowMissingContentWindow()

void ShowMissingContentWindow ( const GRFConfigList &  list)

◆ ShowNewGRFError()

void ShowNewGRFError ( )

Show the first NewGRF error we can find.

Definition at line 45 of file newgrf_gui.cpp.

References _grfconfig, INVALID_STRING_ID, SetDParam(), SetDParamStr(), ShowErrorMessage(), WL_CRITICAL, and WL_ERROR.

Referenced by _GenerateWorld(), and InitializeWindowsAndCaches().

◆ ShowNewGRFInfo()

static void ShowNewGRFInfo ( const GRFConfig c,
const Rect r,
bool  show_params 
)
static

Definition at line 71 of file newgrf_gui.cpp.

◆ ShowNewGRFSettings()

void ShowNewGRFSettings ( bool  editable,
bool  show_params,
bool  exec_changes,
GRFConfigList &  config 
)

Setup the NewGRF gui.

Parameters
editableallow the user to make changes to the grfconfig in the window
show_paramsshow information about what parameters are set for the grf files
exec_changesif changes are made to the list (editable is true), apply these changes immediately or only update the list
configThe GRFConfigList that will be shown.

Definition at line 1985 of file newgrf_gui.cpp.

References CloseWindowByClass(), and WC_GAME_OPTIONS.

Referenced by MenuClickSettings(), SaveLoadWindow::OnClick(), GenerateLandscapeWindow::OnClick(), SelectGameWindow::OnClick(), and NetworkGameWindow::OnClick().

◆ ShowNewGRFTextfileWindow()

void ShowNewGRFTextfileWindow ( TextfileType  file_type,
const GRFConfig c 
)

Definition at line 575 of file newgrf_gui.cpp.

◆ ShowSavePresetWindow()

static void ShowSavePresetWindow ( const char *  initial_text)
static

Open the window for saving a preset.

Parameters
initial_textInitial text to display in the edit box, or nullptr.

Definition at line 2143 of file newgrf_gui.cpp.

References CloseWindowByClass(), and WC_SAVE_PRESET.

Referenced by NewGRFWindow::OnClick().

◆ UpdateNewGRFScanStatus()

void UpdateNewGRFScanStatus ( uint  num,
const char *  name 
)

Update the NewGRF scan status.

Parameters
numThe number of NewGRFs scanned so far.
nameThe name of the last scanned NewGRF.

Definition at line 2251 of file newgrf_gui.cpp.

References FindWindowByClass(), ScanProgressWindow::UpdateNewGRFScanStatus(), and WC_MODAL_PROGRESS.

Referenced by GRFFileScanner::AddFile().

Variable Documentation

◆ _nested_newgrf_actives_widgets

constexpr NWidgetPart _nested_newgrf_actives_widgets[]
staticconstexpr

Definition at line 1768 of file newgrf_gui.cpp.

◆ _nested_newgrf_availables_widgets

constexpr NWidgetPart _nested_newgrf_availables_widgets[]
staticconstexpr

Definition at line 1823 of file newgrf_gui.cpp.

◆ _nested_newgrf_infopanel_widgets

constexpr NWidgetPart _nested_newgrf_infopanel_widgets[]
staticconstexpr

Definition at line 1856 of file newgrf_gui.cpp.

◆ _nested_newgrf_parameter_widgets

constexpr NWidgetPart _nested_newgrf_parameter_widgets[]
staticconstexpr

Definition at line 508 of file newgrf_gui.cpp.

◆ _nested_newgrf_widgets

constexpr NWidgetPart _nested_newgrf_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetStringTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
NWidget(WWT_PANEL, COLOUR_MAUVE),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE), SetResizeWidgetTypeTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetValues widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
std::unique_ptr< NWidgetBase > NewGRFDisplay()
Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:41
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition widget_type.h:31

Definition at line 1909 of file newgrf_gui.cpp.

◆ _nested_save_preset_widgets

constexpr NWidgetPart _nested_save_preset_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_SAVE_PRESET_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_INSET, COLOUR_GREY, WID_SVP_PRESET_LIST), SetPadding(2, 1, 2, 2),
SetToolTip(STR_SAVE_PRESET_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SVP_SCROLLBAR), EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SVP_EDITBOX), SetPadding(2, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
SetStringTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_CANCEL), SetStringTip(STR_SAVE_PRESET_CANCEL, STR_SAVE_PRESET_CANCEL_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_SAVE), SetStringTip(STR_SAVE_PRESET_SAVE, STR_SAVE_PRESET_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
}
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
@ WID_SVP_SAVE
Button to save the preset.
@ WID_SVP_PRESET_LIST
List with available preset names.
@ WID_SVP_SCROLLBAR
Scrollbar for the list available preset names.
@ WID_SVP_CANCEL
Button to cancel saving the preset.
@ WID_SVP_EDITBOX
Edit box for changing the preset name.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:42
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76

Widget parts of the save preset window.

Definition at line 1992 of file newgrf_gui.cpp.

◆ _nested_scan_progress_widgets

constexpr NWidgetPart _nested_scan_progress_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_NEWGRF_SCAN_MESSAGE), SetFill(1, 0),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_BAR), SetFill(1, 0),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(400, 0),
}
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
@ WID_SP_PROGRESS_BAR
Simple progress bar.
@ WID_SP_PROGRESS_TEXT
Text explaining what is happening.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:39

Widgets for the progress window.

Definition at line 2150 of file newgrf_gui.cpp.