OpenTTD Source 20260421-master-gc2fbc6fdeb
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();
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 = {
59 NWidget(WWT_CAPTION, Colours::LightBlue, WID_EP_CAPTION), SetToolTip(STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
71 NWidget(WWT_PUSHTXTBTN, Colours::LightBlue, WID_EP_PREV), SetStringTip(STR_ENGINE_PREVIEW_PREVIOUS, STR_ENGINE_PREVIEW_PREVIOUS_TOOLTIP), SetFill(1, 0),
72 NWidget(WWT_DROPDOWN, Colours::LightBlue, WID_EP_LIST), SetToolTip(STR_ENGINE_PREVIEW_ENGINE_LIST_TOOLTIP), SetFill(1, 0),
73 NWidget(WWT_PUSHTXTBTN, Colours::LightBlue, 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();
93
94 /* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
95 this->flags.Set(WindowFlag::Sticky);
96 }
97
98 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
99 {
100 if (widget == WID_EP_CAPTION) {
101 if (this->engines.size() <= 1) return GetString(STR_ENGINE_PREVIEW_CAPTION);
102 return GetString(STR_ENGINE_PREVIEW_CAPTION_COUNT, this->selected_index + 1, this->engines.size());
103 }
104
105 if (widget == WID_EP_LIST) {
106 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);
107 }
108
109 return this->Window::GetWidgetString(widget, stringid);
110 }
111
112 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
113 {
114 switch (widget) {
115 case WID_EP_QUESTION: {
116 /* Get size of engine sprite, on loan from depot_gui.cpp */
117 EngineImageType image_type = EIT_PREVIEW;
118
119 /* First determine required the horizontal size. */
120 this->vehicle_space = ScaleSpriteTrad(40);
121 for (const EngineID &engine : this->engines) {
122 uint x, y;
123 int x_offs, y_offs;
124
125 const Engine *e = Engine::Get(engine);
126 switch (e->type) {
127 default: NOT_REACHED();
128 case VEH_TRAIN: GetTrainSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
129 case VEH_ROAD: GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
130 case VEH_SHIP: GetShipSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
131 case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
132 }
133
134 this->vehicle_space = std::max<int>(this->vehicle_space, y - y_offs);
135 size.width = std::max(size.width, x + std::abs(x_offs));
136 }
137
138 /* Then account for the description of each vehicle. */
139 int height = 0;
140 for (const EngineID &engine : this->engines) {
141 int title_height = GetStringHeight(GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), size.width);
142 int body_height = GetStringHeight(GetEngineInfoString(engine), size.width);
143 height = std::max(height, title_height + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FontSize::Normal) + this->vehicle_space + body_height);
144 }
145
146 size.height = height;
147 break;
148 }
149
150 case WID_EP_LIST: {
151 size.width = 0;
152 int index = 0;
153 for (const EngineID &engine : this->engines) {
154 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews))).width);
155 ++index;
156 }
157 size.width += padding.width;
158 break;
159 }
160 }
161 }
162
163 void DrawWidget(const Rect &r, WidgetID widget) const override
164 {
165 if (widget != WID_EP_QUESTION) return;
166
167 if (this->selected_index >= this->engines.size()) return;
168
169 EngineID engine = this->engines[selected_index];
170 int y = DrawStringMultiLine(r, GetString(STR_ENGINE_PREVIEW_MESSAGE, GetEngineCategoryName(engine)), TC_FROMSTRING, SA_HOR_CENTER | SA_TOP) + WidgetDimensions::scaled.vsep_wide;
171
172 DrawString(r.left, r.right, y, GetString(STR_ENGINE_NAME, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), TC_BLACK, SA_HOR_CENTER);
174
175 DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
176
177 y += this->vehicle_space;
178 DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
179 }
180
181 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
182 {
183 switch (widget) {
184 case WID_EP_YES:
185 if (this->selected_index < this->engines.size()) {
186 Command<Commands::WantEnginePreview>::Post(this->engines[this->selected_index]);
187 }
188 [[fallthrough]];
189
190 case WID_EP_NO:
191 if (!_shift_pressed) {
192 this->engines.erase(this->engines.begin() + this->selected_index);
193 this->InvalidateData();
194 }
195 break;
196
197 case WID_EP_PREV:
198 this->selected_index = (this->selected_index + this->engines.size() - 1) % this->engines.size();
199 this->SetDirty();
200 break;
201
202 case WID_EP_NEXT:
203 this->selected_index = (this->selected_index + 1) % this->engines.size();
204 this->SetDirty();
205 break;
206
207 case WID_EP_LIST:
208 ShowDropDownList(this, this->BuildDropdownList(), static_cast<int>(this->selected_index), widget);
209 break;
210 }
211 }
212
213 void OnDropdownSelect(WidgetID widget, int index, int) override
214 {
215 if (widget != WID_EP_LIST) return;
216 this->selected_index = index % this->engines.size();
217 this->SetDirty();
218 }
219
225 {
226 DropDownList list;
227
228 int index = 0;
229 for (const EngineID &engine : this->engines) {
230 list.push_back(MakeDropDownListStringItem(GetString(STR_ENGINE_PREVIEW_ENGINE_LIST, index + 1, PackEngineNameDParam(engine, EngineNameContext::PreviewNews)), index, false, false));
231 ++index;
232 }
233
234 return list;
235 }
236
237 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
238 {
239 if (!gui_scope) return;
240
241 /* Remove engines that are no longer eligible for preview. */
242 for (auto it = this->engines.begin(); it != this->engines.end(); /* nothing */) {
243 if (Engine::Get(*it)->preview_company != _local_company) {
244 it = this->engines.erase(it);
245 } else {
246 ++it;
247 }
248 }
249
250 /* If no engines are remaining, close the window. */
251 if (this->engines.empty()) this->Close();
252
253 /* Ensure selection is valid. */
254 if (this->selected_index >= this->engines.size()) this->selected_index = this->engines.size() - 1;
255
256 this->SetWidgetsDisabledState(this->engines.size() <= 1, WID_EP_PREV, WID_EP_LIST, WID_EP_NEXT);
257 }
258
264 {
265 if (std::ranges::find_if(this->engines, [engine](const EngineID &e) { return e == engine; }) != std::end(this->engines)) return;
266
267 this->engines.push_back(engine);
268
269 this->InvalidateData();
270 this->ReInit();
271 }
272};
273
274static WindowDesc _engine_preview_desc(
275 WDP_CENTER, {}, 0, 0,
278 _nested_engine_preview_widgets
279);
280
281
282void ShowEnginePreviewWindow(EngineID engine)
283{
285 if (w == nullptr) {
286 new EnginePreviewWindow(_engine_preview_desc, engine);
287 } else {
288 w->AddEngineToPreview(engine);
289 }
290}
291
298{
300 return cap.GetSum<uint>();
301}
302
308static std::string GetPreviewRunningCostString(const Engine &e)
309{
310 return GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR, e.GetRunningCost());
311}
312
313static std::string GetTrainEngineInfoString(const Engine &e)
314{
315 std::stringstream res;
316
317 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
318 res << '\n';
319
320 if (e.VehInfo<RailVehicleInfo>().railtypes.Count() > 1) {
321 std::string railtypes{};
322 std::string_view list_separator = GetListSeparator();
323
324 for (const auto &rt : _sorted_railtypes) {
325 if (!e.VehInfo<RailVehicleInfo>().railtypes.Test(rt)) continue;
326
327 if (!railtypes.empty()) railtypes += list_separator;
328 AppendStringInPlace(railtypes, GetRailTypeInfo(rt)->strings.name);
329 }
330 res << GetString(STR_ENGINE_PREVIEW_RAILTYPES, railtypes);
331 res << '\n';
332 }
333
334 bool is_maglev = true;
335 for (RailType rt : e.VehInfo<RailVehicleInfo>().railtypes) {
337 }
338
339 if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && !is_maglev) {
340 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
341 res << '\n';
342 } else {
343 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower());
344 res << '\n';
345 }
346
348 res << '\n';
349
350 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
351 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
352
353 return res.str();
354}
355
356static std::string GetAircraftEngineInfoString(const Engine &e)
357{
358 std::stringstream res;
359
360 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
361 res << '\n';
362
363 if (uint16_t range = e.GetRange(); range > 0) {
364 res << GetString(STR_ENGINE_PREVIEW_TYPE_RANGE, e.GetAircraftTypeText(), range);
365 res << '\n';
366 } else {
367 res << GetString(STR_ENGINE_PREVIEW_TYPE, e.GetAircraftTypeText());
368 res << '\n';
369 }
370
372 res << '\n';
373
374 CargoType cargo = e.GetDefaultCargoType();
375 uint16_t mail_capacity;
376 uint capacity = e.GetDisplayDefaultCapacity(&mail_capacity);
377 if (mail_capacity > 0) {
378 res << GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
379 } else {
380 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
381 }
382
383 return res.str();
384}
385
386static std::string GetRoadVehEngineInfoString(const Engine &e)
387{
388 std::stringstream res;
389
390 if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
391 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
392 res << '\n';
393 } else {
394 res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
395 res << '\n';
396 res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
397 res << '\n';
398 }
399
401 res << '\n';
402
403 uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
404 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
405
406 return res.str();
407}
408
409static std::string GetShipEngineInfoString(const Engine &e)
410{
411 std::stringstream res;
412
413 res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
414 res << '\n';
415
417 res << '\n';
418
419 res << GetString(STR_ENGINE_PREVIEW_CAPACITY, e.GetDefaultCargoType(), e.GetDisplayDefaultCapacity());
420
421 return res.str();
422}
423
424
431std::string GetEngineInfoString(EngineID engine)
432{
433 const Engine &e = *Engine::Get(engine);
434
435 switch (e.type) {
436 case VEH_TRAIN:
437 return GetTrainEngineInfoString(e);
438
439 case VEH_ROAD:
440 return GetRoadVehEngineInfoString(e);
441
442 case VEH_SHIP:
443 return GetShipEngineInfoString(e);
444
445 case VEH_AIRCRAFT:
446 return GetAircraftEngineInfoString(e);
447
448 default: NOT_REACHED();
449 }
450}
451
462void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
463{
464 const Engine *e = Engine::Get(engine);
465
466 switch (e->type) {
467 case VEH_TRAIN:
468 DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
469 break;
470
471 case VEH_ROAD:
472 DrawRoadVehEngine(left, right, preferred_x, y, engine, pal, image_type);
473 break;
474
475 case VEH_SHIP:
476 DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
477 break;
478
479 case VEH_AIRCRAFT:
480 DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
481 break;
482
483 default: NOT_REACHED();
484 }
485}
486
492void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
493{
494 if (el.size() < 2) return;
495 std::sort(el.begin(), el.end(), compare);
496}
497
505void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
506{
507 if (num_items < 2) return;
508 assert(begin < el.size());
509 assert(begin + num_items <= el.size());
510 std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
511}
512
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 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:471
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
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>).
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:115
const T GetSum() const
Get the sum of all cargo amounts.
Definition cargo_type.h:121
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:2164
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: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
@ WDP_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