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 <http://www.gnu.org/licenses/>.
6  */
7 
8 /** @file vehicle_gui.h Functions related to the vehicle's GUIs. */
9 
10 #ifndef VEHICLE_GUI_H
11 #define VEHICLE_GUI_H
12 
13 #include "window_type.h"
14 #include "vehicle_type.h"
15 #include "order_type.h"
16 #include "station_type.h"
17 #include "engine_type.h"
18 #include "company_type.h"
19 
20 void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit = false);
21 
22 /** The tabs in the train details window */
23 enum TrainDetailsWindowTabs {
24 	TDW_TAB_CARGO = 0, ///< Tab with cargo carried by the vehicles
25 	TDW_TAB_INFO,      ///< Tab with name and value of the vehicles
26 	TDW_TAB_CAPACITY,  ///< Tab with cargo capacity of the vehicles
27 	TDW_TAB_TOTALS,    ///< Tab with sum of total cargo transported
28 };
29 
30 /** Special values for vehicle-related windows for the data parameter of #InvalidateWindowData. */
31 enum VehicleInvalidateWindowData {
32 	VIWD_REMOVE_ALL_ORDERS = -1, ///< Removed / replaced all orders (after deleting / sharing).
33 	VIWD_MODIFY_ORDERS     = -2, ///< Other order modifications.
34 	VIWD_CONSIST_CHANGED   = -3, ///< Vehicle composition was changed.
35 	VIWD_AUTOREPLACE       = -4, ///< Autoreplace replaced the vehicle.
36 };
37 
38 /** Extra information about refitted cargo and capacity */
39 struct TestedEngineDetails {
40 	Money cost;           ///< Refit cost
41 	CargoID cargo;        ///< Cargo type
42 	uint capacity;        ///< Cargo capacity
43 	uint16 mail_capacity; ///< Mail capacity if available
44 };
45 
46 int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te);
47 
48 void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE);
49 void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip = 0);
50 void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type);
51 void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type);
52 
53 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type);
54 
55 uint ShowRefitOptionsList(int left, int right, int y, EngineID engine);
56 StringID GetCargoSubtypeText(const Vehicle *v);
57 
58 void ShowVehicleListWindow(const Vehicle *v);
59 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type);
60 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationID station);
61 void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile);
62 
63 /**
64  * Get the height of a single vehicle in the GUIs.
65  * @param type the vehicle type to look at
66  * @return the height
67  */
GetVehicleHeight(VehicleType type)68 static inline uint GetVehicleHeight(VehicleType type)
69 {
70 	return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;
71 }
72 
73 int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type);
74 int GetVehicleWidth(const Vehicle *v, EngineImageType image_type);
75 
76 /** Dimensions of a cell in the purchase/depot windows. */
77 struct VehicleCellSize {
78 	uint height;       ///< Vehicle cell height.
79 	uint extend_left;  ///< Extend of the cell to the left.
80 	uint extend_right; ///< Extend of the cell to the right.
81 };
82 
83 VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type);
84 
85 /**
86  * Get WindowClass for vehicle list of given vehicle type
87  * @param vt vehicle type to check
88  * @return corresponding window class
89  * @note works only for company buildable vehicle types
90  */
GetWindowClassForVehicleType(VehicleType vt)91 static inline WindowClass GetWindowClassForVehicleType(VehicleType vt)
92 {
93 	switch (vt) {
94 		default: NOT_REACHED();
95 		case VEH_TRAIN:    return WC_TRAINS_LIST;
96 		case VEH_ROAD:     return WC_ROADVEH_LIST;
97 		case VEH_SHIP:     return WC_SHIPS_LIST;
98 		case VEH_AIRCRAFT: return WC_AIRCRAFT_LIST;
99 	}
100 }
101 
102 /* Unified window procedure */
103 void ShowVehicleViewWindow(const Vehicle *v);
104 bool VehicleClicked(const Vehicle *v);
105 void StartStopVehicle(const Vehicle *v, bool texteffect);
106 
107 Vehicle *CheckClickOnVehicle(const struct Viewport *vp, int x, int y);
108 
109 void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip);
110 void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type);
111 
112 #endif /* VEHICLE_GUI_H */
113