Change: Improve graph period markings (#8732)
[openttd-github.git] / src / vehicle_gui_base.h
blobf89b81ffbe0156b7ec0279a81bff2ac14465cad6
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 */
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"
21 #include <iterator>
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 {
50 enum GroupBy : byte {
51 GB_NONE,
52 GB_SHARED_ORDERS,
54 GB_END,
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.
62 Scrollbar *vscroll;
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 {
69 ADI_REPLACE,
70 ADI_SERVICE,
71 ADI_DEPOT,
72 ADI_ADD_SHARED,
73 ADI_REMOVE_ALL,
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) {
97 case GB_NONE:
98 return vehicle_group_none_sorter_names;
99 case GB_SHARED_ORDERS:
100 return vehicle_group_shared_orders_sorter_names;
101 default:
102 NOT_REACHED();
106 VehicleGroupSortFunction * const *GetVehicleSorterFuncs()
108 switch (this->grouping) {
109 case GB_NONE:
110 return vehicle_group_none_sorter_funcs;
111 case GB_SHARED_ORDERS:
112 return vehicle_group_shared_orders_sorter_funcs;
113 default:
114 NOT_REACHED();
119 uint GetVehicleListHeight(VehicleType type, uint divisor = 1);
121 struct Sorting {
122 Listing aircraft;
123 Listing roadveh;
124 Listing ship;
125 Listing train;
128 extern BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
129 extern Sorting _sorting[BaseVehicleListWindow::GB_END];
131 #endif /* VEHICLE_GUI_BASE_H */