32#include "table/strings.h"
45 default: NOT_REACHED();
49 return STR_ENGINE_PREVIEW_AIRCRAFT;
51 return STR_ENGINE_PREVIEW_SHIP;
58static constexpr std::initializer_list<NWidgetPart> _nested_engine_preview_widgets = {
91 this->engines.push_back(engine);
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());
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);
123 for (
const EngineID &engine : this->engines) {
129 default: NOT_REACHED();
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));
142 for (
const EngineID &engine : this->engines) {
155 for (
const EngineID &engine : this->engines) {
159 size.width += padding.width;
169 if (this->selected_index >= this->engines.size())
return;
179 y += this->vehicle_space;
188 Command<Commands::WantEnginePreview>::Post(this->engines[this->selected_index]);
194 this->engines.erase(this->engines.begin() + this->selected_index);
200 this->selected_index = (this->selected_index + this->engines.size() - 1) % this->engines.size();
205 this->selected_index = (this->selected_index + 1) % this->engines.size();
218 this->selected_index = index % this->engines.size();
231 for (
const EngineID &engine : this->engines) {
239 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
241 if (!gui_scope)
return;
244 for (
auto it = this->engines.begin(); it != this->engines.end(); ) {
246 it = this->engines.erase(it);
253 if (this->engines.empty()) this->
Close();
256 if (this->selected_index >= this->engines.size()) this->selected_index = this->engines.size() - 1;
267 if (std::ranges::find_if(this->engines, [engine](
const EngineID &e) {
return e == engine; }) != std::end(this->engines))
return;
269 this->engines.push_back(engine);
281 _nested_engine_preview_widgets
285void ShowEnginePreviewWindow(
EngineID engine)
303 return cap.
GetSum<uint>();
316static std::string GetTrainEngineInfoString(
const Engine &e)
318 std::stringstream res;
324 std::string railtypes{};
330 if (!railtypes.empty()) railtypes += list_separator;
333 res <<
GetString(STR_ENGINE_PREVIEW_RAILTYPES, railtypes);
337 bool is_maglev =
true;
342 if (
_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && !is_maglev) {
359static std::string GetAircraftEngineInfoString(
const Engine &e)
361 std::stringstream res;
366 if (uint16_t range = e.
GetRange(); range > 0) {
378 uint16_t mail_capacity;
380 if (mail_capacity > 0) {
381 res <<
GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
383 res <<
GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
389static std::string GetRoadVehEngineInfoString(
const Engine &e)
391 std::stringstream res;
393 if (
_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
412static std::string GetShipEngineInfoString(
const Engine &e)
414 std::stringstream res;
440 return GetTrainEngineInfoString(e);
443 return GetRoadVehEngineInfoString(e);
446 return GetShipEngineInfoString(e);
449 return GetAircraftEngineInfoString(e);
451 default: NOT_REACHED();
471 DrawTrainEngine(left, right, preferred_x, y, engine, pal, image_type);
479 DrawShipEngine(left, right, preferred_x, y, engine, pal, image_type);
483 DrawAircraftEngine(left, right, preferred_x, y, engine, pal, image_type);
486 default: NOT_REACHED();
497 if (el.size() < 2)
return;
498 std::sort(el.begin(), el.end(), compare);
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);
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.
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.
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
uint16_t GetRange() const
Get the range of an aircraft type.
Money GetCost() const
Return how much a new engine costs.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
VehicleType type
Vehicle type, ie VehicleType::Road, VehicleType::Train, etc.
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.
Money GetRunningCost() const
Return how much the running costs of this engine are.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
StringID name
Name of this rail type.
StringID new_loco
Name of an engine for this type of rail in the engine preview GUI.
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.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
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.
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.
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.
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.
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.
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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
bool _shift_pressed
Is Shift pressed?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
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.
@ Normal
Index of the normal font in the font tables.
@ SA_TOP
Top align the text.
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_CENTER
Center both horizontally and vertically.
uint32_t PaletteID
The number of the palette.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
#define Point
Macro that prevents name conflicts between included headers.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType
Enumeration for all possible railtypes.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
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.
Types related to global configuration settings.
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 of base types and functions in a cross-platform compatible way.
std::string_view GetListSeparator()
Get the list separator string for the current language.
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...
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
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.
const T GetSum() const
Get the sum of all cargo amounts.
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.
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Specification of a rectangle with absolute coordinates of all edges.
Information about a road vehicle.
RoadType roadtype
Road type.
High level window description.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
WindowFlags flags
Window flags.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
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.
Functions related to vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_PREVIEW
Vehicle drawn in preview window, news, ...
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
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.
@ Center
Center the window.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ 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.