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/>.
8 /** @file vehicle_gui_base.h Functions/classes shared between the different vehicle list GUIs. */
10 #ifndef VEHICLE_GUI_BASE_H
11 #define VEHICLE_GUI_BASE_H
13 #include "core/smallvec_type.hpp"
14 #include "date_type.h"
15 #include "economy_type.h"
16 #include "sortlist_type.h"
17 #include "vehiclelist.h"
18 #include "window_gui.h"
19 #include "widgets/dropdown_type.h"
23 typedef GUIList
<const Vehicle
*> GUIVehicleList
;
25 struct GUIVehicleGroup
{
26 VehicleList::const_iterator vehicles_begin
; ///< Pointer to beginning element of this vehicle group.
27 VehicleList::const_iterator vehicles_end
; ///< Pointer to past-the-end element of this vehicle group.
28 Money display_profit_this_year
; ///< Total profit for the vehicle group this year.
29 Money display_profit_last_year
; ///< Total profit for the vehicle group laste year.
30 Date age
; ///< Age in days of oldest vehicle in the group.
32 GUIVehicleGroup(VehicleList::const_iterator vehicles_begin
, VehicleList::const_iterator vehicles_end
, Money display_profit_this_year
, Money display_profit_last_year
, Date age
)
33 : vehicles_begin(vehicles_begin
), vehicles_end(vehicles_end
), display_profit_this_year(display_profit_this_year
), display_profit_last_year(display_profit_last_year
), age(age
) {}
35 std::ptrdiff_t NumVehicles() const
37 return std::distance(vehicles_begin
, vehicles_end
);
39 const Vehicle
*GetSingleVehicle() const
41 assert(NumVehicles() == 1);
42 return vehicles_begin
[0];
46 typedef GUIList
<GUIVehicleGroup
> GUIVehicleGroupList
;
48 struct BaseVehicleListWindow
: public Window
{
57 GroupBy grouping
; ///< How we want to group the list.
58 VehicleList vehicles
; ///< List of vehicles. This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt.
59 GUIVehicleGroupList vehgroups
; ///< List of (groups of) vehicles. This stores iterators of `vehicles`, and should be rebuilt if `vehicles` is structurally changed.
60 Listing
*sorting
; ///< Pointer to the vehicle type related sorting.
61 byte unitnumber_digits
; ///< The number of digits of the highest unit number.
63 VehicleListIdentifier vli
; ///< Identifier of the vehicle list we want to currently show.
65 typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction
;
66 typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction
;
68 enum ActionDropdownItem
{
76 static const StringID vehicle_depot_name
[];
77 static const StringID vehicle_group_by_names
[];
78 static const StringID vehicle_group_none_sorter_names
[];
79 static const StringID vehicle_group_shared_orders_sorter_names
[];
80 static VehicleGroupSortFunction
* const vehicle_group_none_sorter_funcs
[];
81 static VehicleGroupSortFunction
* const vehicle_group_shared_orders_sorter_funcs
[];
83 BaseVehicleListWindow(WindowDesc
*desc
, WindowNumber wno
);
85 void UpdateSortingFromGrouping();
87 void DrawVehicleListItems(VehicleID selected_vehicle
, int line_height
, const Rect
&r
) const;
88 void UpdateVehicleGroupBy(GroupBy group_by
);
89 void SortVehicleList();
90 void BuildVehicleList();
91 Dimension
GetActionDropdownSize(bool show_autoreplace
, bool show_group
);
92 DropDownList
BuildActionDropdownList(bool show_autoreplace
, bool show_group
);
94 const StringID
*GetVehicleSorterNames()
96 switch (this->grouping
) {
98 return vehicle_group_none_sorter_names
;
99 case GB_SHARED_ORDERS
:
100 return vehicle_group_shared_orders_sorter_names
;
106 VehicleGroupSortFunction
* const *GetVehicleSorterFuncs()
108 switch (this->grouping
) {
110 return vehicle_group_none_sorter_funcs
;
111 case GB_SHARED_ORDERS
:
112 return vehicle_group_shared_orders_sorter_funcs
;
119 uint
GetVehicleListHeight(VehicleType type
, uint divisor
= 1);
128 extern BaseVehicleListWindow::GroupBy _grouping
[VLT_END
][VEH_COMPANY_END
];
129 extern Sorting _sorting
[BaseVehicleListWindow::GB_END
];
131 #endif /* VEHICLE_GUI_BASE_H */