OpenTTD Source 20260129-master-g2bb01bd0e4
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 "dropdown_func.h"
12#include "window_gui.h"
13#include "engine_base.h"
14#include "command_func.h"
15#include "strings_func.h"
16#include "engine_gui.h"
18#include "vehicle_func.h"
19#include "company_func.h"
20#include "rail.h"
21#include "road.h"
22#include "settings_type.h"
23#include "train.h"
24#include "roadveh.h"
25#include "ship.h"
26#include "aircraft.h"
27#include "engine_cmd.h"
28#include "zoom_func.h"
29
31
32#include "table/strings.h"
33
34#include "safeguards.h"
35
42{
43 const Engine *e = Engine::Get(engine);
44 switch (e->type) {
45 default: NOT_REACHED();
46 case VEH_ROAD:
48 case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT;
49 case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP;
50 case VEH_TRAIN:
51 assert(e->VehInfo<RailVehicleInfo>().railtypes.Any());
52 return GetRailTypeInfo(e->VehInfo<RailVehicleInfo>().railtypes.GetNthSetBit(0).value())->strings.new_loco;
53 }
54}
55
56static constexpr std::initializer_list<NWidgetPart> _nested_engine_preview_widgets = {
58 NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
59 NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_EP_CAPTION), SetToolTip(STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
61 NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
63 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
65 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NO), SetStringTip(STR_QUIT_NO), SetFill(1, 0),
66 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_YES), SetStringTip(STR_QUIT_YES), SetFill(1, 0),
71 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_PREV), SetStringTip(STR_ENGINE_PREVIEW_PREVIOUS, STR_ENGINE_PREVIEW_PREVIOUS_TOOLTIP), SetFill(1, 0),
72 NWidget(WWT_DROPDOWN, COLOUR_LIGHT_BLUE, WID_EP_LIST), SetToolTip(STR_ENGINE_PREVIEW_ENGINE_LIST_TOOLTIP), SetFill(1, 0),
73 NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NEXT), SetStringTip(STR_ENGINE_PREVIEW_NEXT, STR_ENGINE_PREVIEW_NEXT_TOOLTIP), SetFill(1, 0),
75};
76
78 int vehicle_space = 0;
79 size_t selected_index = 0;
80 std::vector<EngineID> engines;
81
88 {
89 this->engines.push_back(engine);
90
91 this->InitNested();
92
93 /* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
95 }
96
97 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
98 {
99 if (widget == WID_EP_CAPTION) {
100 if (this->engines.size() <= 1) return GetString(STR_ENGINE_PREVIEW_CAPTION);
101 return GetString(STR_ENGINE_PREVIEW_CAPTION_COUNT, this->selected_index + 1, this->engines.size());
102 }
103
104 if (widget == WID_EP_LIST) {
105 return this->selected_index < this->engines.size() ? GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, this->selected_index + 1, this->engines[this->selected_index]) : GetString(STR_INVALID_VEHICLE);
106 }
107
108 return this->Window::GetWidgetString(widget, stringid);
109 }
110
111 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
112 {
113 switch (widget) {
114 case WID_EP_QUESTION: {
115 /* Get size of engine sprite, on loan from depot_gui.cpp */
116 EngineImageType image_type = EIT_PREVIEW;
117
118 /* First determine required the horizontal size. */
119 this->vehicle_space = ScaleSpriteTrad(40);
120 for (const EngineID &engine : this->engines) {
121 uint x, y;
122 int x_offs, y_offs;
123
124 const Engine *e = Engine::Get(engine);
125 switch (e->type) {
126 default: NOT_REACHED();
127 case VEH_TRAIN: GetTrainSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
128 case VEH_ROAD: GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
129 case VEH_SHIP: GetShipSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
130 case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
131 }
132
133 this->vehicle_space = std::max<int>(this->vehicle_space, y - y_offs);
134 size.width = std::max(size.width, x + std::abs(x_offs));
135 }
136
137 /* Then account for the description of each vehicle. */
138 int height = 0;
139 for (const EngineID &engine : this->engines) {
140 int title_height = GetStringHeight(GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), size.width);
141 int body_height = GetStringHeight(GetEngineInfoString(engine), size.width);
142 height = std::max(height, title_height + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space + body_height);
143 }
144
145 size.height = height;
146 break;
147 }
148
149 case WID_EP_LIST: {
150 size.width = 0;
151 int index = 0;
152 for (const EngineID &engine : this->engines) {
153 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews))).width);
154 ++index;
155 }
156 size.width += padding.width;
157 break;
158 }
159 }
160 }
161
162 void DrawWidget(const Rect &r, WidgetID widget) const override
163 {
164 if (widget != WID_EP_QUESTION) return;
165
166 if (this->selected_index >= this->engines.size()) return;
167
168 EngineID engine = this->engines[selected_index];
169 int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
170
171 DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TC_BLACK, SA_HOR_CENTER);
173
174 DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
175
176 y += this->vehicle_space;
177 DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
178 }
179
180 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
181 {
182 switch (widget) {
183 case WID_EP_YES:
184 if (this->selected_index < this->engines.size()) {
185 Command<Commands::WantEnginePreview>::Post(this->engines[this->selected_index]);
186 }
187 [[fallthrough]];
188
189 case WID_EP_NO:
190 if (!_shift_pressed) {
191 this->engines.erase(this->engines.begin() + this->selected_index);
192 this->InvalidateData();
193 }
194 break;
195
196 case WID_EP_PREV:
197 this->selected_index = (this->selected_index + this->engines.size() - 1) % this->engines.size();
198 this->SetDirty();
199 break;
200
201 case WID_EP_NEXT:
202 this->selected_index = (this->selected_index + 1) % this->engines.size();
203 this->SetDirty();
204 break;
205
206 case WID_EP_LIST:
207 ShowDropDownList(this, this->BuildDropdownList(), static_cast<int>(this->selected_index), widget);
208 break;
209 }
210 }
211
212 void OnDropdownSelect(WidgetID widget, int index, int) override
213 {
214 if (widget != WID_EP_LIST) return;
215 this->selected_index = index % this->engines.size();
216 this->SetDirty();
217 }
218
224 {
225 DropDownList list;
226
227 int index = 0;
228 for (const EngineID &engine : this->engines) {
229 list.push_back(MakeDropDownListStringItem(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), index, false, false));
230 ++index;
231 }
232
233 return list;
234 }
235
236 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
237 {
238 if (!gui_scope) return;
239
240 /* Remove engines that are no longer eligible for preview. */
241 for (auto it = this->engines.begin(); it != this->engines.end(); /* nothing */) {
242 if (Engine::Get(*it)->preview_company != _local_company) {
243 it = this->engines.erase(it);
244 } else {
245 ++it;
246 }
247 }
248
249 /* If no engines are remaining, close the window. */
250 if (this->engines.empty()) this->Close();
251
252 /* Ensure selection is valid. */
253 if (this->selected_index >= this->engines.size()) this->selected_index = this->engines.size() - 1;
254
255 this->SetWidgetsDisabledState(this->engines.size() <= 1, WID_EP_PREV, WID_EP_LIST, WID_EP_NEXT);
256 }
257
263 {
264 if (std::ranges::find_if(this->engines, [engine](const EngineID &e) { return e == engine; }) != std::end(this->engines)) return;
265
266 this->engines.push_back(engine);
267
268 this->InvalidateData();
269 this->ReInit();
270 }
271};
272
273static WindowDesc _engine_preview_desc(
274 WDP_CENTER, {}, 0, 0,
277 _nested_engine_preview_widgets
278);
279
280
281void ShowEnginePreviewWindow(EngineID engine)
282{
284 if (w == nullptr) {
285 new EnginePreviewWindow(_engine_preview_desc, engine);
286 } else {
287 w->AddEngineToPreview(engine);
288 }
289}
290
297{
299 return cap.GetSum<uint>();
300}
301
307static std::string GetPreviewRunningCostString(const Engine &e)
308{
309 return GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR, e.GetRunningCost());
310}
311
312static std::string GetTrainEngineInfoString(const Engine &e)
313{
314 std::stringstream res;
315
316 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
317 res << '\n';
318
319 if (e.VehInfo<RailVehicleInfo>().railtypes.Count() > 1) {
320 std::string railtypes{};
321 std::string_view list_separator = GetListSeparator();
322
323 for (const auto &rt : _sorted_railtypes) {
324 if (!e.VehInfo<RailVehicleInfo>().railtypes.Test(rt)) continue;
325
326 if (!railtypes.empty()) railtypes += list_separator;
327 AppendStringInPlace(railtypes, GetRailTypeInfo(rt)->strings.name);
328 }
329 res << GetString(STR_ENGINE_PREVIEW_RAILTYPES, railtypes);
330 res << '\n';
331 }
332
333 bool is_maglev = true;
334 for (RailType rt : e.VehInfo<RailVehicleInfo>().railtypes) {
336 }
337
338 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && !is_maglev) {
339 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
340 res << '\n';
341 } else {
342 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower());
343 res << '\n';
344 }
345
347 res << '\n';
348
349 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
350 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
351
352 return res.str();
353}
354
355static std::string GetAircraftEngineInfoString(const Engine &e)
356{
357 std::stringstream res;
358
359 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
360 res << '\n';
361
362 if (uint16_t range = e.GetRange(); range > 0) {
363 res << GetString(STR_ENGINE_PREVIEW_TYPE_RANGE, e.GetAircraftTypeText(), range);
364 res << '\n';
365 } else {
366 res << GetString(STR_ENGINE_PREVIEW_TYPE, e.GetAircraftTypeText());
367 res << '\n';
368 }
369
371 res << '\n';
372
373 CargoType cargo = e.GetDefaultCargoType();
374 uint16_t mail_capacity;
375 uint capacity = e.GetDisplayDefaultCapacity(&mail_capacity);
376 if (mail_capacity > 0) {
377 res << GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
378 } else {
379 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
380 }
381
382 return res.str();
383}
384
385static std::string GetRoadVehEngineInfoString(const Engine &e)
386{
387 std::stringstream res;
388
390 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
391 res << '\n';
392 } else {
393 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
394 res << '\n';
395 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
396 res << '\n';
397 }
398
400 res << '\n';
401
402 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
403 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
404
405 return res.str();
406}
407
408static std::string GetShipEngineInfoString(const Engine &e)
409{
410 std::stringstream res;
411
412 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
413 res << '\n';
414
416 res << '\n';
417
418 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, e.GetDefaultCargoType(), e.GetDisplayDefaultCapacity());
419
420 return res.str();
421}
422
423
430std::string GetEngineInfoString(EngineID engine)
431{
432 const Engine &e = *Engine::Get(engine);
433
434 switch (e.type) {
435 case VEH_TRAIN:
436 return GetTrainEngineInfoString(e);
437
438 case VEH_ROAD:
439 return GetRoadVehEngineInfoString(e);
440
441 case VEH_SHIP:
442 return GetShipEngineInfoString(e);
443
444 case VEH_AIRCRAFT:
445 return GetAircraftEngineInfoString(e);
446
447 default: NOT_REACHED();
448 }
449}
450
460void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
461{
462 const Engine *e = Engine::Get(engine);
463
464 switch (e->type) {
465 case VEH_TRAIN:
466 DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
467 break;
468
469 case VEH_ROAD:
470 DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
471 break;
472
473 case VEH_SHIP:
474 DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
475 break;
476
477 case VEH_AIRCRAFT:
478 DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
479 break;
480
481 default: NOT_REACHED();
482 }
483}
484
491{
492 if (el.size() < 2) return;
493 std::sort(el.begin(), el.end(), compare);
494}
495
503void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
504{
505 if (num_items < 2) return;
506 assert(begin < el.size());
507 assert(begin + num_items <= el.size());
508 std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
509}
510
Base for aircraft.
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).
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Functions related to articulated vehicles.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
uint Count() const
Count the number of set bits.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition engine.cpp:470
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition engine.cpp:393
uint16_t GetRange() const
Get the range of an aircraft type.
Definition engine.cpp:456
Money GetCost() const
Return how much a new engine costs.
Definition engine.cpp:321
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition engine.cpp:361
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition engine.cpp:411
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition engine_base.h:62
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition engine_base.h:94
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition engine.cpp:284
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition engine.cpp:429
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
Definition rail.h:215
StringID name
Name of this rail type.
Definition rail.h:165
struct RailTypeInfo::@21 strings
Strings associated with the rail type.
StringID new_loco
Name of an engine for this type of rail in the engine preview GUI.
Definition rail.h:170
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:82
struct RoadTypeInfo::@24 strings
Strings associated with the rail type.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
Show a drop down list.
Definition dropdown.cpp:418
Functions related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Base class for engines.
Command definitions related to engines.
std::string GetEngineInfoString(EngineID engine)
Get a multi-line string with some technical data, describing the engine.
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
static std::string GetPreviewRunningCostString(const Engine &e)
Get preview running cost string for an engine.
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
StringID GetEngineCategoryName(EngineID engine)
Return the category of an engine.
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>)
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui.
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
Definition engine_gui.h:33
void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw a road vehicle engine.
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.
@ PreviewNews
Name is shown in exclusive preview or newspaper.
@ Maglev
Maglev acceleration model.
Types related to the engine widgets.
@ WID_EP_CAPTION
The caption for the question.
@ WID_EP_QUESTION
The container for the question.
@ WID_EP_NO
No button.
@ WID_EP_LIST
Dropdown menu to jump to entries.
@ WID_EP_NEXT
Next button.
@ WID_EP_YES
Yes button.
@ WID_EP_PREV
Previous button.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:715
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:39
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:897
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:668
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:785
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ SA_TOP
Top align the text.
Definition gfx_type.h:393
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
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 SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:968
Rail specific functions.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Definition rail_cmd.cpp:47
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
Road specific functions.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
Road vehicle states.
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).
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
Types related to global configuration settings.
Base for ships.
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
Definition of base types and functions in a cross-platform compatible way.
std::string_view GetListSeparator()
Get the list separator string for the current language.
Definition strings.cpp:299
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
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class for storing amounts of cargo.
Definition cargo_type.h:111
const T GetSum() const
Get the sum of all cargo amounts.
Definition cargo_type.h:117
Dimensions (a width and height) of a rectangle in 2D.
void AddEngineToPreview(EngineID engine)
Adds another engine to the engine preview window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
size_t selected_index
The currently displayed index in the list of engines.
std::vector< EngineID > engines
List of engine IDs to display preview news for.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int vehicle_space
The space to show the vehicle image.
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.
EnginePreviewWindow(WindowDesc &desc, EngineID engine)
Construct a new Engine Preview window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
DropDownList BuildDropdownList()
Build the dropdown list of new engines.
VehicleSettings vehicle
options for vehicles
static Titem * Get(auto index)
Returns Titem with given index.
const Tindex index
Index of this pool item.
Information about a rail vehicle.
Definition engine_type.h:74
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Definition engine_type.h:78
Specification of a rectangle with absolute coordinates of all edges.
Information about a road vehicle.
RoadType roadtype
Road type.
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
uint8_t train_acceleration_model
realistic acceleration for trains
High level window description.
Definition window_gui.h:168
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:980
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1104
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3240
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:506
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1822
WindowFlags flags
Window flags.
Definition window_gui.h:301
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:313
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
Base for the train class.
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).
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition vehicle.cpp:2135
Functions related to vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ EqualSize
Containers should keep all their (resizing) children equally large.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1168
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ Sticky
Window is made sticky by user.
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107