OpenTTD

Data Structures | Typedefs | Functions | Variables
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 "widgets/dropdown_type.h"`
`#include "widgets/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 "widgets/newgrf_widget.h"`
`#include "widgets/misc_widget.h"`
`#include "table/sprites.h"`
`#include <map>`
`#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...
class | DropDownListPresetItem
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, 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, uint x, uint y, uint right, uint bottom, bool show_params)
static void | OpenGRFParameterWindow (GRFConfig *c, bool editable)
void | ShowNewGRFTextfileWindow (TextfileType file_type, const GRFConfig *c)
static void | FillGrfidMap (const GRFConfig *c, GrfIdMap *grfid_map)
| Add all grf configs from c into the map. More...
static void | NewGRFConfirmationCallback (Window *w, bool confirmed)
| Callback function for the newgrf 'apply changes' confirmation window. More...
static void | ShowSavePresetWindow (const char *initial_text)
| Open the window for saving a preset. More...
void | ShowMissingContentWindow (const GRFConfig *list)
| Show the content list window with all missing grfs from the given list. More...
NWidgetBase * | NewGRFDisplay (int *biggest_index)
| Construct nested container widget for managing the lists and the info panel of the NewGRF GUI. More...
void | ShowNewGRFSettings (bool editable, bool show_params, bool exec_changes, GRFConfig **config)
| Setup the NewGRF gui. More...
void | UpdateNewGRFScanStatus (uint num, const char *name)
| Update the NewGRF scan status. More...

## Variables
static const NWidgetPart | _nested_newgrf_parameter_widgets []
static WindowDesc | _newgrf_parameters_desc (WDP_CENTER, "settings_newgrf_config", 500, 208, WC_GRF_PARAMETERS, WC_NONE, 0, _nested_newgrf_parameter_widgets, lengthof(_nested_newgrf_parameter_widgets))
| Window definition for the change grf parameters window.
static GRFPresetList | _grf_preset_list
| List of known NewGRF presets. More...
static const NWidgetPart | _nested_newgrf_actives_widgets []
static const NWidgetPart | _nested_newgrf_availables_widgets []
static const NWidgetPart | _nested_newgrf_infopanel_widgets []
static const NWidgetPart | _nested_newgrf_widgets []
static WindowDesc | _newgrf_desc (WDP_CENTER, "settings_newgrf", 300, 263, WC_GAME_OPTIONS, WC_NONE, 0, _nested_newgrf_widgets, lengthof(_nested_newgrf_widgets))
static const NWidgetPart | _nested_save_preset_widgets []
| Widget parts of the save preset window. More...
static WindowDesc | _save_preset_desc (WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WDF_MODAL, _nested_save_preset_widgets, lengthof(_nested_save_preset_widgets))
| Window description of the preset save window. More...
static const NWidgetPart | _nested_scan_progress_widgets []
| Widgets for the progress window. More...
static WindowDesc | _scan_progress_desc (WDP_CENTER, NULL, 0, 0, WC_MODAL_PROGRESS, WC_NONE, 0, _nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets))
| Description of the widgets and other settings of the window. More...

## Detailed Description

GUI to change NewGRF settings.

Definition in file newgrf_gui.cpp.

## Function Documentation

## ◆ FillGrfidMap()

static void FillGrfidMap | ( | const GRFConfig * | c,
|  | GrfIdMap * | grfid_map
| ) |  |
| static

Add all grf configs from c into the map.

Parameters

  c | Grf list to add.
  grfid_map | Map to add them to.

Definition at line 595 of file newgrf_gui.cpp.

References GRFIdentifier::grfid, GRFConfig::ident, NewGRFConfirmationCallback(), GRFConfig::next, and ShowSavePresetWindow().

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

  w | Window which is calling this callback
  confirmed | boolean value, true when yes was clicked, false otherwise

Definition at line 1967 of file newgrf_gui.cpp.

References _grfconfig, NewGRFWindow::active_sel, NewGRFWindow::actives, NewGRFWindow::avails, CopyGRFConfigList(), DeleteWindowByClass(), GUIList< T, F >::ForceRebuild(), GamelogGRFUpdate(), GamelogStartAction(), GamelogStopAction(), GLAT_GRF, Window::InvalidateData(), GRFConfig::next, NewGRFWindow::orig_list, ReInitAllWindows(), ReloadNewGRFData(), WC_BUILD_OBJECT, and WC_GRF_PARAMETERS.

Referenced by FillGrfidMap().

## ◆ NewGRFDisplay()

NWidgetBase* NewGRFDisplay | ( | int * | biggest_index | ) |

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

Definition at line 1923 of file newgrf_gui.cpp.

References lengthof, MakeNWidgets(), and max().

## ◆ ShowMissingContentWindow()

void ShowMissingContentWindow | ( | const GRFConfig * | list | ) |

Show the content list window with all missing grfs from the given list.

Parameters

  list | The list of grfs to check for missing / not exactly matching ones.

Definition at line 1554 of file newgrf_gui.cpp.

References SmallVector< T, S >::Append(), BSWAP32(), CONTENT_TYPE_NEWGRF, ContentInfo::DOES_NOT_EXIST, NewGRFWindow::filter_funcs, GRFConfig::flags, GCF_COMPATIBLE, GCS_NOT_FOUND, GRFConfig::GetName(), GRFIdentifier::grfid, HasBit(), GRFConfig::ident, NewGRFWindow::last_filtering, NewGRFWindow::last_sorting, lastof, SmallVector< T, S >::Length(), ContentInfo::md5sum, GRFIdentifier::md5sum, ContentInfo::name, GRFConfig::next, GRFConfig::original_md5sum, ShowNetworkContentListWindow(), NewGRFWindow::sorter_funcs, ContentInfo::state, GRFConfig::status, strecpy(), ContentInfo::type, and ContentInfo::unique_id.

Referenced by ClientNetworkContentSocketHandler::RemoveCallback().

## ◆ ShowNewGRFSettings()

void ShowNewGRFSettings | ( | bool | editable,
|  | bool | show_params,
|  | bool | exec_changes,
|  | GRFConfig ** | config
| ) |  |

Setup the NewGRF gui.

Parameters

  editable | allow the user to make changes to the grfconfig in the window
  show_params | show information about what parameters are set for the grf files
  exec_changes | if changes are made to the list (editable is true), apply these changes immediately or only update the list
  config | pointer to a linked-list of grfconfig's that will be shown

Definition at line 2005 of file newgrf_gui.cpp.

References DeleteWindowByClass(), and WC_GAME_OPTIONS.

Referenced by NewGRFScanCallback::~NewGRFScanCallback().

## ◆ ShowSavePresetWindow()

static void ShowSavePresetWindow | ( | const char * | initial_text | ) |
| static

Open the window for saving a preset.

Parameters

  initial_text | Initial text to display in the edit box, or `NULL`.

Definition at line 2161 of file newgrf_gui.cpp.

References DeleteWindowByClass(), and WC_SAVE_PRESET.

Referenced by FillGrfidMap().

## ◆ UpdateNewGRFScanStatus()

void UpdateNewGRFScanStatus | ( | uint | num,
|  | const char * | name
| ) |  |

Update the NewGRF scan status.

Parameters

  num | The number of NewGRFs scanned so far.
  name | The name of the last scanned NewGRF.

Definition at line 2279 of file newgrf_gui.cpp.

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

Referenced by GRFFileScanner::AddFile(), and ScanNewGRFFiles().

## Variable Documentation

## ◆ _grf_preset_list

GRFPresetList _grf_preset_list
| static

List of known NewGRF presets.

See also
  GetGRFPresetList

Definition at line 568 of file newgrf_gui.cpp.

## ◆ _nested_newgrf_widgets

const NWidgetPart _nested_newgrf_widgets[]
| static

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_MAUVE),
NWidgetFunction(NewGRFDisplay), SetPadding(WD_RESIZEBOX_WIDTH, WD_RESIZEBOX_WIDTH, 2, WD_RESIZEBOX_WIDTH),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
EndContainer(),
EndContainer(),
}
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
NewGRFDisplay
NWidgetBase * NewGRFDisplay(int *biggest_index)
Construct nested container widget for managing the lists and the info panel of the NewGRF GUI...
Definition: newgrf_gui.cpp:1923
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1146
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1046
NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:79
WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
WD_RESIZEBOX_WIDTH
Width of a resize box widget.
Definition: window_gui.h:112
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983

Definition at line 1938 of file newgrf_gui.cpp.

## ◆ _nested_save_preset_widgets

const NWidgetPart _nested_save_preset_widgets[]
| static

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_SAVE_PRESET_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_INSET, COLOUR_GREY, WID_SVP_PRESET_LIST), SetPadding(2, 1, 0, 2),
SetDataTip(0x0, STR_SAVE_PRESET_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SVP_SCROLLBAR), EndContainer(),
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SVP_SCROLLBAR),
EndContainer(),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SVP_EDITBOX), SetPadding(3, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
SetDataTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_CANCEL), SetDataTip(STR_SAVE_PRESET_CANCEL, STR_SAVE_PRESET_CANCEL_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_SAVE), SetDataTip(STR_SAVE_PRESET_SAVE, STR_SAVE_PRESET_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
}
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
WID_SVP_PRESET_LIST
List with available preset names.
Definition: newgrf_widget.h:66
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:71
WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:51
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1046
WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
WID_SVP_CANCEL
Button to cancel saving the preset.
Definition: newgrf_widget.h:69
WID_SVP_SCROLLBAR
Scrollbar for the list available preset names.
Definition: newgrf_widget.h:67
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
WID_SVP_EDITBOX
Edit box for changing the preset name.
Definition: newgrf_widget.h:68
WID_SVP_SAVE
Button to save the preset.
Definition: newgrf_widget.h:70
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095

Widget parts of the save preset window.

Definition at line 2012 of file newgrf_gui.cpp.

## ◆ _nested_scan_progress_widgets

const NWidgetPart _nested_scan_progress_widgets[]
| static

Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
NWidget(WWT_LABEL, INVALID_COLOUR), SetDataTip(STR_NEWGRF_SCAN_MESSAGE, STR_NULL), 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),
EndContainer(),
EndContainer(),
EndContainer(),
}
WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
WWT_LABEL
Centered label.
Definition: widget_type.h:57
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
WID_SP_PROGRESS_BAR
Simple progress bar.
Definition: newgrf_widget.h:75
WID_SP_PROGRESS_TEXT
Text explaining what is happening.
Definition: newgrf_widget.h:76
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076

Widgets for the progress window.

Definition at line 2168 of file newgrf_gui.cpp.

## ◆ _save_preset_desc

WindowDesc _save_preset_desc(WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WDF_MODAL, _nested_save_preset_widgets, lengthof(_nested_save_preset_widgets))
| static

Window description of the preset save window.

## ◆ _scan_progress_desc

WindowDesc _scan_progress_desc(WDP_CENTER, NULL, 0, 0, WC_MODAL_PROGRESS, WC_NONE, 0, _nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets))
| static

Description of the widgets and other settings of the window.