OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
19 #include "table/strings.h"
29 void CcBuildWagon(
Commands,
const CommandCost &result,
VehicleID new_veh_id, uint, uint16_t,
CargoArray,
TileIndex tile,
EngineID,
bool,
CargoID,
ClientID)
31 if (result.
Failed())
return;
36 if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
37 if (found !=
nullptr)
return;
43 if (found !=
nullptr) {
44 found = found->
Last();
65 int dragged_width = 0;
66 for (
Train *t =
Train::Get(selection); t !=
nullptr; t = chain ? t->
Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() :
nullptr)) {
67 dragged_width += t->GetDisplayImageWidth(
nullptr);
70 int drag_hlight_left = rtl ? std::max(px - dragged_width + 1, 0) : px;
71 int drag_hlight_right = rtl ? px : std::min(px + dragged_width, max_width) - 1;
72 int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
74 if (drag_hlight_width > 0) {
76 int top = y - height / 2;
77 Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
82 return drag_hlight_width;
102 int max_width = r.
Width();
109 int px = rtl ? max_width + skip : -skip;
111 bool sel_articulated =
false;
113 bool drag_at_end_of_train = (drag_dest == v->
index);
114 for (; v !=
nullptr && (rtl ? px > 0 : px < max_width); v = v->
Next()) {
115 if (dragging && !drag_at_end_of_train && drag_dest == v->
index) {
118 px += rtl ? -drag_hlight_width : drag_hlight_width;
124 if (rtl ? px + width > 0 : px - width < max_width) {
133 if (v->
index == selection) {
135 highlight_l = rtl ? px - width : px;
136 highlight_r = rtl ? px - 1 : px + width - 1;
137 sel_articulated =
true;
138 }
else if ((_cursor.
vehchain && highlight_r != 0) || sel_articulated) {
140 highlight_l -= width;
142 highlight_r += width;
146 px += rtl ? -width : width;
149 if (dragging && drag_at_end_of_train) {
155 if (highlight_l != highlight_r) {
159 Rect hr = {highlight_l, 0, highlight_r, height - 1};
175 return this->cargo != other.
cargo || this->subtype != other.
subtype;
181 return !(this->cargo != other.
cargo);
209 str =
FreightWagonMult(item->
cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
214 DrawString(left, right, y, str, TC_LIGHT_BLUE);
230 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
235 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
255 str =
FreightWagonMult(item->
cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY;
259 str = STR_VEHICLE_INFO_NO_CAPACITY;
280 auto item = std::find(std::begin(summary), std::end(summary), new_item);
281 if (item == std::end(summary)) {
282 item = summary.emplace(std::end(summary));
283 item->cargo = new_item.
cargo;
284 item->subtype = new_item.
subtype;
287 item->source = INVALID_STATION;
325 max_cargo[v->cargo_type] += v->cargo_cap;
355 int line_height = r.
Height();
356 int sprite_y_offset = line_height / 2;
362 int x = rtl ? r.right : r.left;
363 for (; v !=
nullptr && vscroll_pos > -vscroll_cap; v = v->
GetNextVehicle()) {
373 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
376 if (e->
GetGRF() !=
nullptr) {
382 seq.
Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->
vehstatus &
VS_CRASHED) != 0);
384 px += rtl ? -width : width;
390 if (separate_sprite_row) {
398 for (uint i = 0; i < num_lines; i++) {
399 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
400 int py = r.top - line_height * vscroll_pos + text_y_offset;
401 if (i > 0 || separate_sprite_row) {
409 DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
422 DrawString(dr.left, dr.right, py, STR_VEHICLE_INFO_NO_CAPACITY);
426 default: NOT_REACHED();
436 Money feeder_share = 0;
438 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
439 act_cargo[u->cargo_type] += u->cargo.StoredCount();
440 max_cargo[u->cargo_type] += u->cargo_cap;
441 feeder_share += u->cargo.GetFeederShare();
445 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
452 if (max_cargo[cid] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
458 DrawString(ir.left, ir.right, y + text_y_offset,
FreightWagonMult(cid) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
463 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
Money value
Value of the vehicle.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
uint16_t cargo_cap
total capacity
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
T * Next() const
Get next vehicle in the chain.
uint GetCount() const
Get the amount of cargos that have an amount.
bool vehchain
vehicle chain is dragged
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Tindex index
Index of this pool item.
Class for storing amounts of cargo.
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Specification of a cargo type.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
EngineImageType
Visualisation contexts of vehicles and engines.
static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details capacity tab for the given vehicle at the given position.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
uint32_t PaletteID
The number of the palette.
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
Collects the cargo transported.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
uint capacity
Amount that can be carried.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
StationID source
One of the source stations.
uint8_t freight_trains
value to multiply the weight of cargo by
Common return value for all commands.
@ FS_NORMAL
Index of the normal font in the font tables.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
TrainDetailsWindowTabs
The tabs in the train details window.
TileIndex tile
Current tile index.
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.
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
EngineID engine_type
The type of engine used for this vehicle.
@ VS_CRASHED
Vehicle is crashed.
Sprite sequence for a vehicle part.
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
VehicleCargoList cargo
The cargo this vehicle is carrying.
bool Failed() const
Did this command fail?
GameSettings _settings_game
Game settings of a running game or the scenario editor.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
static Train * Get(size_t index)
Gets vehicle with given index.
static CargoSummary _cargo_summary
Reused container of cargo details.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
'Train' is either a loco or a wagon.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
static const uint TRAIN_DETAILS_MAX_INDENT
Maximum indent level in the train details window; wider than this and we start on a new line.
uint32_t VehicleID
The type all our vehicle IDs have.
static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
Draw the details info tab for the given vehicle at the given position.
Coordinates of a point in 2D.
@ WC_TRAINS_LIST
Trains list; Window numbers:
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
@ RAILVEH_WAGON
simple wagon, not motorized
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
uint8_t FreightWagonMult(CargoID cargo)
Return the cargo weight multiplier to use for a rail vehicle.
static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
Highlight the position where a rail vehicle is dragged over by drawing a light gray background.
Helper struct for the cargo details information.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
CargoID cargo
The cargo that is carried.
static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details cargo tab for the given vehicle at the given position.
bool CanCarryCargo() const
Determines whether an engine can carry something.
ClientID
'Unique' identifier to be given to clients
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
@ VehicleDetails
Name is shown in the vehicle details GUI.
bool operator!=(const CargoSummaryItem &other) const
Used by CargoSummary::Find() and similar functions.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Direction
Defines the 8 directions on the map.
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
Vehicle * Last()
Get the last vehicle of this vehicle chain.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
uint amount
Amount that is carried.
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
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.
CargoID cargo_type
type of cargo this vehicle is carrying
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
VehicleSettings vehicle
options for vehicles
uint16_t EngineID
Unique identification number of an engine.
Commands
List of commands.
StringID subtype
STR_EMPTY if none.
int Width() const
Get width of Rect.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Specification of a rectangle with absolute coordinates of all edges.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ FR_BORDERONLY
Draw border only, no background.
Data about how and where to blit pixels.
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.