OpenTTD Source  1.11.0-beta1
vehicle_gui_base.h
Go to the documentation of this file.
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 
10 #ifndef VEHICLE_GUI_BASE_H
11 #define VEHICLE_GUI_BASE_H
12 
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"
20 
21 #include <iterator>
22 
24 
26  VehicleList::const_iterator vehicles_begin;
27  VehicleList::const_iterator vehicles_end;
31 
32  GUIVehicleGroup(VehicleList::const_iterator vehicles_begin, VehicleList::const_iterator vehicles_end, Money display_profit_this_year, Money display_profit_last_year, Date age)
34 
35  std::ptrdiff_t NumVehicles() const
36  {
37  return std::distance(vehicles_begin, vehicles_end);
38  }
39  const Vehicle *GetSingleVehicle() const
40  {
41  assert(NumVehicles() == 1);
42  return vehicles_begin[0];
43  }
44 };
45 
47 
48 struct BaseVehicleListWindow : public Window {
49 
50  enum GroupBy : byte {
51  GB_NONE,
52  GB_SHARED_ORDERS,
53 
54  GB_END,
55  };
56 
57  GroupBy grouping;
62  Scrollbar *vscroll;
64 
65  typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
66  typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
67 
68  enum ActionDropdownItem {
69  ADI_REPLACE,
70  ADI_SERVICE,
71  ADI_DEPOT,
72  ADI_ADD_SHARED,
73  ADI_REMOVE_ALL,
74  };
75 
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[];
82 
84 
85  void UpdateSortingFromGrouping();
86 
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);
93 
94  const StringID *GetVehicleSorterNames()
95  {
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();
103  }
104  }
105 
106  VehicleGroupSortFunction * const *GetVehicleSorterFuncs()
107  {
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();
115  }
116  }
117 };
118 
119 uint GetVehicleListHeight(VehicleType type, uint divisor = 1);
120 
121 struct Sorting {
122  Listing aircraft;
123  Listing roadveh;
124  Listing ship;
125  Listing train;
126 };
127 
128 extern BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
129 extern Sorting _sorting[BaseVehicleListWindow::GB_END];
130 
131 #endif /* VEHICLE_GUI_BASE_H */
BaseVehicleListWindow::GetActionDropdownSize
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group)
Compute the size for the Action dropdown.
Definition: vehicle_gui.cpp:237
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition: vehiclelist.h:53
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
BaseVehicleListWindow::grouping
GroupBy grouping
How we want to group the list.
Definition: vehicle_gui_base.h:57
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
GUIList
List template of 'things' T to sort in a GUI.
Definition: sortlist_type.h:46
vehiclelist.h
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
smallvec_type.hpp
GetVehicleListHeight
uint GetVehicleListHeight(VehicleType type, uint divisor=1)
Get the height of a vehicle in the vehicle list GUIs.
Definition: vehicle_gui.cpp:1495
BaseVehicleListWindow::sorting
Listing * sorting
Pointer to the vehicle type related sorting.
Definition: vehicle_gui_base.h:60
GUIVehicleGroup::vehicles_begin
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
Definition: vehicle_gui_base.h:26
GUIVehicleGroup::age
Date age
Age in days of oldest vehicle in the group.
Definition: vehicle_gui_base.h:30
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
WindowDesc
High level window description.
Definition: window_gui.h:166
window_gui.h
GUIVehicleGroup::display_profit_this_year
Money display_profit_this_year
Total profit for the vehicle group this year.
Definition: vehicle_gui_base.h:28
BaseVehicleListWindow::vli
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
Definition: vehicle_gui_base.h:63
BaseVehicleListWindow::BuildActionDropdownList
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group)
Display the Action dropdown window.
Definition: vehicle_gui.cpp:259
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
VEH_COMPANY_END
@ VEH_COMPANY_END
Last company-ownable type.
Definition: vehicle_type.h:29
BaseVehicleListWindow
Definition: vehicle_gui_base.h:48
GUIList< GUIVehicleGroup >::SortFunction
bool SortFunction(const GUIVehicleGroup &, const GUIVehicleGroup &)
Signature of sort function.
Definition: sortlist_type.h:48
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
dropdown_type.h
sortlist_type.h
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
date_type.h
BaseVehicleListWindow::DrawVehicleListItems
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
Definition: vehicle_gui.cpp:1515
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Sorting
Definition: vehicle_gui_base.h:121
GUIVehicleGroup
Definition: vehicle_gui_base.h:25
BaseVehicleListWindow::vehgroups
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
Definition: vehicle_gui_base.h:59
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
BaseVehicleListWindow::vehicles
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
Definition: vehicle_gui_base.h:58
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
BaseVehicleListWindow::unitnumber_digits
byte unitnumber_digits
The number of digits of the highest unit number.
Definition: vehicle_gui_base.h:61
Window
Data structure for an opened window.
Definition: window_gui.h:276
economy_type.h
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
GUIVehicleGroup::display_profit_last_year
Money display_profit_last_year
Total profit for the vehicle group laste year.
Definition: vehicle_gui_base.h:29
GUIVehicleGroup::vehicles_end
VehicleList::const_iterator vehicles_end
Pointer to past-the-end element of this vehicle group.
Definition: vehicle_gui_base.h:27