OpenTTD Source: src/engine_gui.cpp Source File

OpenTTD Source 15.0-RC2

engine_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "window_gui.h"
12#include "engine_base.h"
13#include "command_func.h"
14#include "strings_func.h"
15#include "engine_gui.h"
16#include "articulated_vehicles.h"
17#include "vehicle_func.h"
18#include "company_func.h"
19#include "rail.h"
20#include "road.h"
21#include "settings_type.h"
22#include "train.h"
23#include "roadveh.h"
24#include "ship.h"
25#include "aircraft.h"
26#include "engine_cmd.h"
27#include "zoom_func.h"
28
29#include "widgets/engine_widget.h"
30
31#include "table/strings.h"
32
33#include "safeguards.h"
34
40 StringID GetEngineCategoryName(EngineID engine)
41{
42 const Engine *e = Engine::Get(engine);
43 switch (e->type) {
44 default: NOT_REACHED();
45 case VEH_ROAD:
46 return GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->strings.new_engine;
47 case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
48 case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
49 case VEH_TRAIN:
50 assert(e->VehInfo<RailVehicleInfo>().railtypes.Any());
51 return GetRailTypeInfo(e->VehInfo<RailVehicleInfo>().railtypes.GetNthSetBit(0).value())->strings.new_loco;
52 }
53}
54
55static constexpr std::initializer_list<NWidgetPart> _nested_engine_preview_widgets = {
56 NWidget(NWID_HORIZONTAL),
57 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
58 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetStringTip(STR_ENGINE_PREVIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
59 EndContainer(),
60 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
61 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
62 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
63 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(85, WidgetDimensions::unscaled.hsep_wide, 85),
64 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NO), SetStringTip(STR_QUIT_NO), SetFill(1, 0),
65 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_YES), SetStringTip(STR_QUIT_YES), SetFill(1, 0),
66 EndContainer(),
67 EndContainer(),
68 EndContainer(),
69};
70
71 struct EnginePreviewWindow : Window {
72 int vehicle_space = 0; // The space to show the vehicle image
73
74 EnginePreviewWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
75 {
76 this->InitNested(window_number);
77
78 /* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
79 this->flags.Set(WindowFlag::Sticky);
80 }
81
82 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
83 {
84 if (widget != WID_EP_QUESTION) return;
85
86 /* Get size of engine sprite, on loan from depot_gui.cpp */
87 EngineID engine = static_cast<EngineID>(this->window_number);
88 EngineImageType image_type = EIT_PREVIEW;
89 uint x, y;
90 int x_offs, y_offs;
91
92 const Engine *e = Engine::Get(engine);
93 switch (e->type) {
94 default: NOT_REACHED();
95 case VEH_TRAIN: GetTrainSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
96 case VEH_ROAD: GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
97 case VEH_SHIP: GetShipSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
98 case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
99 }
100 this->vehicle_space = std::max<int>(ScaleSpriteTrad(40), y - y_offs);
101
102 size.width = std::max(size.width, x + std::abs(x_offs));
103 size.height = GetStringHeight(GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), size.width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space;
104 size.height += GetStringHeight(GetEngineInfoString(engine), size.width);
105 }
106
107 void DrawWidget(const Rect &r, WidgetID widget) const override
108 {
109 if (widget != WID_EP_QUESTION) return;
110
111 EngineID engine = static_cast<EngineID>(this->window_number);
112 int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
113
114 DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TC_BLACK, SA_HOR_CENTER);
115 y += GetCharacterHeight(FS_NORMAL);
116
117 DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
118
119 y += this->vehicle_space;
120 DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
121 }
122
123 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
124 {
125 switch (widget) {
126 case WID_EP_YES:
127 Command<CMD_WANT_ENGINE_PREVIEW>::Post(static_cast<EngineID>(this->window_number));
128 [[fallthrough]];
129 case WID_EP_NO:
130 if (!_shift_pressed) this->Close();
131 break;
132 }
133 }
134
135 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
136 {
137 if (!gui_scope) return;
138
139 EngineID engine = static_cast<EngineID>(this->window_number);
140 if (Engine::Get(engine)->preview_company != _local_company) this->Close();
141 }
142};
143
144static WindowDesc _engine_preview_desc(
145 WDP_CENTER, {}, 0, 0,
146 WC_ENGINE_PREVIEW, WC_NONE,
147 WindowDefaultFlag::Construction,
148 _nested_engine_preview_widgets
149);
150
151
152void ShowEnginePreviewWindow(EngineID engine)
153{
154 AllocateWindowDescFront<EnginePreviewWindow>(_engine_preview_desc, engine);
155}
156
162uint GetTotalCapacityOfArticulatedParts(EngineID engine)
163{
164 CargoArray cap = GetCapacityOfArticulatedParts(engine);
165 return cap.GetSum<uint>();
166}
167
173 static std::string GetPreviewRunningCostString(const Engine &e)
174{
175 return GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR, e.GetRunningCost());
176}
177
178static std::string GetTrainEngineInfoString(const Engine &e)
179{
180 std::stringstream res;
181
182 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
183 res << '\n';
184
185 if (e.VehInfo<RailVehicleInfo>().railtypes.Count() > 1) {
186 std::string railtypes{};
187 std::string_view list_separator = GetListSeparator();
188
189 for (const auto &rt : _sorted_railtypes) {
190 if (!e.VehInfo<RailVehicleInfo>().railtypes.Test(rt)) continue;
191
192 if (!railtypes.empty()) railtypes += list_separator;
193 AppendStringInPlace(railtypes, GetRailTypeInfo(rt)->strings.name);
194 }
195 res << GetString(STR_ENGINE_PREVIEW_RAILTYPES, railtypes);
196 res << '\n';
197 }
198
199 bool is_maglev = true;
200 for (RailType rt : e.VehInfo<RailVehicleInfo>().railtypes) {
201 is_maglev &= GetRailTypeInfo(rt)->acceleration_type == VehicleAccelerationModel::Maglev;
202 }
203
204 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && !is_maglev) {
205 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
206 res << '\n';
207 } else {
208 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower());
209 res << '\n';
210 }
211
212 res << GetPreviewRunningCostString(e);
213 res << '\n';
214
215 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
216 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
217
218 return res.str();
219}
220
221static std::string GetAircraftEngineInfoString(const Engine &e)
222{
223 std::stringstream res;
224
225 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
226 res << '\n';
227
228 if (uint16_t range = e.GetRange(); range > 0) {
229 res << GetString(STR_ENGINE_PREVIEW_TYPE_RANGE, e.GetAircraftTypeText(), range);
230 res << '\n';
231 } else {
232 res << GetString(STR_ENGINE_PREVIEW_TYPE, e.GetAircraftTypeText());
233 res << '\n';
234 }
235
236 res << GetPreviewRunningCostString(e);
237 res << '\n';
238
239 CargoType cargo = e.GetDefaultCargoType();
240 uint16_t mail_capacity;
241 uint capacity = e.GetDisplayDefaultCapacity(&mail_capacity);
242 if (mail_capacity > 0) {
243 res << GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
244 } else {
245 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
246 }
247
248 return res.str();
249}
250
251static std::string GetRoadVehEngineInfoString(const Engine &e)
252{
253 std::stringstream res;
254
255 if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
256 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
257 res << '\n';
258 } else {
259 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
260 res << '\n';
261 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
262 res << '\n';
263 }
264
265 res << GetPreviewRunningCostString(e);
266 res << '\n';
267
268 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
269 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
270
271 return res.str();
272}
273
274static std::string GetShipEngineInfoString(const Engine &e)
275{
276 std::stringstream res;
277
278 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
279 res << '\n';
280
281 res << GetPreviewRunningCostString(e);
282 res << '\n';
283
284 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, e.GetDefaultCargoType(), e.GetDisplayDefaultCapacity());
285
286 return res.str();
287}
288
289
296std::string GetEngineInfoString(EngineID engine)
297{
298 const Engine &e = *Engine::Get(engine);
299
300 switch (e.type) {
301 case VEH_TRAIN:
302 return GetTrainEngineInfoString(e);
303
304 case VEH_ROAD:
305 return GetRoadVehEngineInfoString(e);
306
307 case VEH_SHIP:
308 return GetShipEngineInfoString(e);
309
310 case VEH_AIRCRAFT:
311 return GetAircraftEngineInfoString(e);
312
313 default: NOT_REACHED();
314 }
315}
316
326 void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
327{
328 const Engine *e = Engine::Get(engine);
329
330 switch (e->type) {
331 case VEH_TRAIN:
332 DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
333 break;
334
335 case VEH_ROAD:
336 DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
337 break;
338
339 case VEH_SHIP:
340 DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
341 break;
342
343 case VEH_AIRCRAFT:
344 DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
345 break;
346
347 default: NOT_REACHED();
348 }
349}
350
356 void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
357{
358 if (el.size() < 2) return;
359 std::sort(el.begin(), el.end(), compare);
360}
361
369 void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
370{
371 if (num_items < 2) return;
372 assert(begin < el.size());
373 assert(begin + num_items <= el.size());
374 std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
375}
376
aircraft.h
Base for aircraft.
GetAircraftSpriteSize
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of an aircraft sprite heading west (used for lists).
Definition aircraft_cmd.cpp:247
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition articulated_vehicles.cpp:136
articulated_vehicles.h
Functions related to articulated vehicles.
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
BaseBitSet::Count
uint Count() const
Count the number of set bits.
Definition base_bitset_type.hpp:237
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
BaseBitSet::GetNthSetBit
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
Definition base_bitset_type.hpp:247
Engine
Definition engine_base.h:38
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition engine.cpp:466
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition engine.cpp:389
Engine::GetRange
uint16_t GetRange() const
Get the range of an aircraft type.
Definition engine.cpp:452
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition engine.cpp:317
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition engine.cpp:357
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition engine.cpp:407
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition engine_base.h:62
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition engine_base.h:115
Engine::GetDefaultCargoType
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition engine_base.h:95
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition engine.cpp:280
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition engine.cpp:425
GUIList< GUIEngineListItem, std::nullptr_t, CargoType >
RailTypeInfo::acceleration_type
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
Definition rail.h:215
RailTypeInfo::name
StringID name
Name of this rail type.
Definition rail.h:165
RailTypeInfo::strings
struct RailTypeInfo::@22 strings
Strings associated with the rail type.
RailTypeInfo::new_loco
StringID new_loco
Name of an engine for this type of rail in the engine preview GUI.
Definition rail.h:170
RoadTypeInfo::strings
struct RoadTypeInfo::@25 strings
Strings associated with the rail type.
RoadTypeInfo::new_engine
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:82
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:98
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
command_func.h
Functions related to commands.
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
company_func.h
Functions related to companies.
engine_base.h
Base class for engines.
engine_cmd.h
Command definitions related to engines.
GetEngineInfoString
std::string GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
Definition engine_gui.cpp:296
EngList_Sort
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition engine_gui.cpp:356
GetPreviewRunningCostString
static std::string GetPreviewRunningCostString(const Engine &e)
Get preview running cost string for an engine.
Definition engine_gui.cpp:173
GetTotalCapacityOfArticulatedParts
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
Definition engine_gui.cpp:162
GetEngineCategoryName
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
Definition engine_gui.cpp:40
EngList_SortPartial
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
Sort selected range of items (on indices @ <begin, begin+num_items-1>)
Definition engine_gui.cpp:369
DrawVehicleEngine
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Definition engine_gui.cpp:326
engine_gui.h
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
EngList_SortTypeFunction
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
Definition engine_gui.h:33
DrawRoadVehEngine
void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw a road vehicle engine.
Definition roadveh_cmd.cpp:149
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition engine_type.h:239
EngineNameContext::PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
VehicleAccelerationModel::Maglev
@ Maglev
Maglev acceleration model.
engine_widget.h
Types related to the engine widgets.
WID_EP_QUESTION
@ WID_EP_QUESTION
The container for the question.
Definition engine_widget.h:15
WID_EP_NO
@ WID_EP_NO
No button.
Definition engine_widget.h:16
WID_EP_YES
@ WID_EP_YES
Yes button.
Definition engine_widget.h:17
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:712
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:39
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:665
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_TOP
@ SA_TOP
Top align the text.
Definition gfx_type.h:393
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1375
SetPadding
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.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
rail.h
Rail specific functions.
_sorted_railtypes
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Definition rail_cmd.cpp:47
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
road.h
Road specific functions.
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
roadveh.h
Road vehicle states.
GetRoadVehSpriteSize
void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a road vehicle sprite heading west (used for lists).
Definition roadveh_cmd.cpp:172
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
settings_type.h
Types related to global configuration settings.
ship.h
Base for ships.
GetShipSpriteSize
void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a ship sprite heading west (used for lists).
Definition ship_cmd.cpp:119
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetListSeparator
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:299
AppendStringInPlace
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
Definition strings.cpp:434
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition strings_func.h:83
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
CargoArray::GetSum
const T GetSum() const
Get the sum of all cargo amounts.
Definition cargo_type.h:117
CommandHelper
Definition command_func.h:83
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
EnginePreviewWindow
Definition engine_gui.cpp:71
EnginePreviewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition engine_gui.cpp:135
EnginePreviewWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition engine_gui.cpp:107
EnginePreviewWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition engine_gui.cpp:82
EnginePreviewWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition engine_gui.cpp:123
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
RailVehicleInfo
Information about a rail vehicle.
Definition engine_type.h:74
RailVehicleInfo::railtypes
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Definition engine_type.h:78
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
RoadVehicleInfo
Information about a road vehicle.
Definition engine_type.h:146
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition engine_type.h:160
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition settings_type.h:521
VehicleSettings::train_acceleration_model
uint8_t train_acceleration_model
realistic acceleration for trains
Definition settings_type.h:520
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1102
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1820
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:301
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
train.h
Base for the train class.
GetTrainSpriteSize
void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a train sprite heading west, or both heads (used for lists).
Definition train_cmd.cpp:579
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition vehicle.cpp:2123
vehicle_func.h
Functions related to vehicles.
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:74
EIT_PREVIEW
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
Definition vehicle_type.h:80
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:541
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WindowFlag::Sticky
@ Sticky
Window is made sticky by user.
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition window_type.h:611
zoom_func.h
Functions related to zooming.
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107