OpenTTD Source 20260512-master-g20b387b91f
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
9
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();
49 return STR_ENGINE_PREVIEW_AIRCRAFT;
51 return STR_ENGINE_PREVIEW_SHIP;
53 assert(e->VehInfo<RailVehicleInfo>().railtypes.Any());
54 return GetRailTypeInfo(e->VehInfo<RailVehicleInfo>().railtypes.GetNthSetBit(0).value())->strings.new_loco;
55 }
56}
57
58static constexpr std::initializer_list<NWidgetPart> _nested_engine_preview_widgets = {
61 NWidget(WWT_CAPTION, Colours::LightBlue, WID_EP_CAPTION), SetToolTip(STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
73 NWidget(WWT_PUSHTXTBTN, Colours::LightBlue, WID_EP_PREV), SetStringTip(STR_ENGINE_PREVIEW_PREVIOUS, STR_ENGINE_PREVIEW_PREVIOUS_TOOLTIP), SetFill(1, 0),
74 NWidget(WWT_DROPDOWN, Colours::LightBlue, WID_EP_LIST), SetToolTip(STR_ENGINE_PREVIEW_ENGINE_LIST_TOOLTIP), SetFill(1, 0),
75 NWidget(WWT_PUSHTXTBTN, Colours::LightBlue, WID_EP_NEXT), SetStringTip(STR_ENGINE_PREVIEW_NEXT, STR_ENGINE_PREVIEW_NEXT_TOOLTIP), SetFill(1, 0),
77};
78
80 int vehicle_space = 0;
81 size_t selected_index = 0;
82 std::vector<EngineID> engines;
83
90 {
91 this->engines.push_back(engine);
92
93 this->InitNested();
95
96 /* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
97 this->flags.Set(WindowFlag::Sticky);
98 }
99
100 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
101 {
102 if (widget == WID_EP_CAPTION) {
103 if (this->engines.size() <= 1) return GetString(STR_ENGINE_PREVIEW_CAPTION);
104 return GetString(STR_ENGINE_PREVIEW_CAPTION_COUNT, this->selected_index + 1, this->engines.size());
105 }
106
107 if (widget == WID_EP_LIST) {
108 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);
109 }
110
111 return this->Window::GetWidgetString(widget, stringid);
112 }
113
114 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
115 {
116 switch (widget) {
117 case WID_EP_QUESTION: {
118 /* Get size of engine sprite, on loan from depot_gui.cpp */
119 EngineImageType image_type = EIT_PREVIEW;
120
121 /* First determine required the horizontal size. */
122 this->vehicle_space = ScaleSpriteTrad(40);
123 for (const EngineID &engine : this->engines) {
124 uint x, y;
125 int x_offs, y_offs;
126
127 const Engine *e = Engine::Get(engine);
128 switch (e->type) {
129 default: NOT_REACHED();
130 case VehicleType::Train: GetTrainSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
131 case VehicleType::Road: GetRoadVehSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
132 case VehicleType::Ship: GetShipSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
133 case VehicleType::Aircraft: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
134 }
135
136 this->vehicle_space = std::max<int>(this->vehicle_space, y - y_offs);
137 size.width = std::max(size.width, x + std::abs(x_offs));
138 }
139
140 /* Then account for the description of each vehicle. */
141 int height = 0;
142 for (const EngineID &engine : this->engines) {
143 int title_height = GetStringHeight(GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), size.width);
144 int body_height = GetStringHeight(GetEngineInfoString(engine), size.width);
145 height = std::max(height, title_height + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FontSize::Normal) + this->vehicle_space + body_height);
146 }
147
148 size.height = height;
149 break;
150 }
151
152 case WID_EP_LIST: {
153 size.width = 0;
154 int index = 0;
155 for (const EngineID &engine : this->engines) {
156 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews))).width);
157 ++index;
158 }
159 size.width += padding.width;
160 break;
161 }
162 }
163 }
164
165 void DrawWidget(const Rect &r, WidgetID widget) const override
166 {
167 if (widget != WID_EP_QUESTION) return;
168
169 if (this->selected_index >= this->engines.size()) return;
170
171 EngineID engine = this->engines[selected_index];
172 int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
173
174 DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TC_BLACK, SA_HOR_CENTER);
176
177 DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
178
179 y += this->vehicle_space;
180 DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
181 }
182
183 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
184 {
185 switch (widget) {
186 case WID_EP_YES:
187 if (this->selected_index < this->engines.size()) {
188 Command<Commands::WantEnginePreview>::Post(this->engines[this->selected_index]);
189 }
190 [[fallthrough]];
191
192 case WID_EP_NO:
193 if (!_shift_pressed) {
194 this->engines.erase(this->engines.begin() + this->selected_index);
195 this->InvalidateData();
196 }
197 break;
198
199 case WID_EP_PREV:
200 this->selected_index = (this->selected_index + this->engines.size() - 1) % this->engines.size();
201 this->SetDirty();
202 break;
203
204 case WID_EP_NEXT:
205 this->selected_index = (this->selected_index + 1) % this->engines.size();
206 this->SetDirty();
207 break;
208
209 case WID_EP_LIST:
210 ShowDropDownList(this, this->BuildDropdownList(), static_cast<int>(this->selected_index), widget);
211 break;
212 }
213 }
214
215 void OnDropdownSelect(WidgetID widget, int index, int) override
216 {
217 if (widget != WID_EP_LIST) return;
218 this->selected_index = index % this->engines.size();
219 this->SetDirty();
220 }
221
227 {
228 DropDownList list;
229
230 int index = 0;
231 for (const EngineID &engine : this->engines) {
232 list.push_back(MakeDropDownListStringItem(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), index, false, false));
233 ++index;
234 }
235
236 return list;
237 }
238
239 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
240 {
241 if (!gui_scope) return;
242
243 /* Remove engines that are no longer eligible for preview. */
244 for (auto it = this->engines.begin(); it != this->engines.end(); /* nothing */) {
245 if (Engine::Get(*it)->preview_company != _local_company) {
246 it = this->engines.erase(it);
247 } else {
248 ++it;
249 }
250 }
251
252 /* If no engines are remaining, close the window. */
253 if (this->engines.empty()) this->Close();
254
255 /* Ensure selection is valid. */
256 if (this->selected_index >= this->engines.size()) this->selected_index = this->engines.size() - 1;
257
258 this->SetWidgetsDisabledState(this->engines.size() <= 1, WID_EP_PREV, WID_EP_LIST, WID_EP_NEXT);
259 }
260
266 {
267 if (std::ranges::find_if(this->engines, [engine](const EngineID &e) { return e == engine; }) != std::end(this->engines)) return;
268
269 this->engines.push_back(engine);
270
271 this->InvalidateData();
272 this->ReInit();
273 }
274};
275
278 WindowPosition::Center, {}, 0, 0,
281 _nested_engine_preview_widgets
282);
283
284
285void ShowEnginePreviewWindow(EngineID engine)
286{
288 if (w == nullptr) {
290 } else {
291 w->AddEngineToPreview(engine);
292 }
293}
294
301{
303 return cap.GetSum<uint>();
304}
305
311static std::string GetPreviewRunningCostString(const Engine &e)
312{
313 return GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR, e.GetRunningCost());
314}
315
316static std::string GetTrainEngineInfoString(const Engine &e)
317{
318 std::stringstream res;
319
320 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
321 res << '\n';
322
323 if (e.VehInfo<RailVehicleInfo>().railtypes.Count() > 1) {
324 std::string railtypes{};
325 std::string_view list_separator = GetListSeparator();
326
327 for (const auto &rt : _sorted_railtypes) {
328 if (!e.VehInfo<RailVehicleInfo>().railtypes.Test(rt)) continue;
329
330 if (!railtypes.empty()) railtypes += list_separator;
331 AppendStringInPlace(railtypes, GetRailTypeInfo(rt)->strings.name);
332 }
333 res << GetString(STR_ENGINE_PREVIEW_RAILTYPES, railtypes);
334 res << '\n';
335 }
336
337 bool is_maglev = true;
338 for (RailType rt : e.VehInfo<RailVehicleInfo>().railtypes) {
340 }
341
342 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && !is_maglev) {
343 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
344 res << '\n';
345 } else {
346 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower());
347 res << '\n';
348 }
349
351 res << '\n';
352
353 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
354 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
355
356 return res.str();
357}
358
359static std::string GetAircraftEngineInfoString(const Engine &e)
360{
361 std::stringstream res;
362
363 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
364 res << '\n';
365
366 if (uint16_t range = e.GetRange(); range > 0) {
367 res << GetString(STR_ENGINE_PREVIEW_TYPE_RANGE, e.GetAircraftTypeText(), range);
368 res << '\n';
369 } else {
370 res << GetString(STR_ENGINE_PREVIEW_TYPE, e.GetAircraftTypeText());
371 res << '\n';
372 }
373
375 res << '\n';
376
377 CargoType cargo = e.GetDefaultCargoType();
378 uint16_t mail_capacity;
379 uint capacity = e.GetDisplayDefaultCapacity(&mail_capacity);
380 if (mail_capacity > 0) {
381 res << GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
382 } else {
383 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
384 }
385
386 return res.str();
387}
388
389static std::string GetRoadVehEngineInfoString(const Engine &e)
390{
391 std::stringstream res;
392
393 if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
394 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
395 res << '\n';
396 } else {
397 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
398 res << '\n';
399 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
400 res << '\n';
401 }
402
404 res << '\n';
405
406 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
407 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
408
409 return res.str();
410}
411
412static std::string GetShipEngineInfoString(const Engine &e)
413{
414 std::stringstream res;
415
416 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
417 res << '\n';
418
420 res << '\n';
421
422 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, e.GetDefaultCargoType(), e.GetDisplayDefaultCapacity());
423
424 return res.str();
425}
426
427
434std::string GetEngineInfoString(EngineID engine)
435{
436 const Engine &e = *Engine::Get(engine);
437
438 switch (e.type) {
440 return GetTrainEngineInfoString(e);
441
443 return GetRoadVehEngineInfoString(e);
444
446 return GetShipEngineInfoString(e);
447
449 return GetAircraftEngineInfoString(e);
450
451 default: NOT_REACHED();
452 }
453}
454
465void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
466{
467 const Engine *e = Engine::Get(engine);
468
469 switch (e->type) {
471 DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
472 break;
473
475 DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
476 break;
477
479 DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
480 break;
481
483 DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
484 break;
485
486 default: NOT_REACHED();
487 }
488}
489
495void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
496{
497 if (el.size() < 2) return;
498 std::sort(el.begin(), el.end(), compare);
499}
500
508void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
509{
510 if (num_items < 2) return;
511 assert(begin < el.size());
512 assert(begin + num_items <= el.size());
513 std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
514}
515
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.
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
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 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:493
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition engine.cpp:415
uint16_t GetRange() const
Get the range of an aircraft type.
Definition engine.cpp:478
Money GetCost() const
Return how much a new engine costs.
Definition engine.cpp:343
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition engine.cpp:383
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition engine.cpp:433
VehicleType type
Vehicle type, ie VehicleType::Road, VehicleType::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:306
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition engine.cpp:451
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
Definition rail.h:215
StringID name
Name of this rail type.
Definition rail.h:165
StringID new_loco
Name of an engine for this type of rail in the engine preview GUI.
Definition rail.h:170
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:82
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
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.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:587
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>).
static WindowDesc _engine_preview_desc(WindowPosition::Center, {}, 0, 0, WC_ENGINE_PREVIEW, WC_NONE, WindowDefaultFlag::Construction, _nested_engine_preview_widgets)
Window definition for the engine preview window.
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.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
Definition engine_type.h:26
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 StringParameter.
@ PreviewNews
Name is shown in exclusive preview or newspaper.
@ Maglev
Maglev acceleration model.
Definition engine_type.h:50
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:88
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:717
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:40
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:900
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:669
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:788
@ 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
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ LightBlue
Light blue.
Definition gfx_type.h:290
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:980
#define Point
Macro that prevents name conflicts between included headers.
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:301
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:120
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:117
const T GetSum() const
Get the sum of all cargo amounts.
Definition cargo_type.h:123
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.
static Engine * Get(auto index)
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.
High level window description.
Definition window_gui.h:168
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:992
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1117
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3262
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:518
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
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1846
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1836
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:2160
Functions related to vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
@ Ship
Ship vehicle type.
@ Aircraft
Aircraft vehicle type.
@ Road
Road vehicle type.
@ 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:1181
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:153
@ Sticky
Window is made sticky by user.
Definition window_gui.h:233
@ Center
Center the window.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:51
@ 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