Files
@ r28486:aff297ed5a05
Branch filter:
Location: cpp/openttd-patchpack/source/src/vehicle_gui_base.h - annotation
r28486:aff297ed5a05
5.6 KiB
text/x-c
Codechange: Allow constexpr NWidgetPart construction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r26528:7330214f8231 r27166:64e04a3ef9b1 r24472:86d98d2f4c47 r10122:8be97f532491 r24964:cc3c5c9ac075 r16068:f32ba8cfc408 r14248:a9050881acd7 r15505:306dfef4fc70 r10122:8be97f532491 r28236:3864664b5c22 r10122:8be97f532491 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24964:cc3c5c9ac075 r24472:86d98d2f4c47 r24964:cc3c5c9ac075 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r27166:64e04a3ef9b1 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24964:cc3c5c9ac075 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r28236:3864664b5c22 r24472:86d98d2f4c47 r13602:30f9b380fb13 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24473:6e405cbcc588 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r26528:7330214f8231 r26528:7330214f8231 r26528:7330214f8231 r26528:7330214f8231 r26528:7330214f8231 r15769:4a935f419828 r26528:7330214f8231 r26528:7330214f8231 r28181:c7e5e74aec76 r26528:7330214f8231 r28224:bb1a33d7a0f2 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r10122:8be97f532491 r15505:306dfef4fc70 r15505:306dfef4fc70 r15505:306dfef4fc70 r15505:306dfef4fc70 r15505:306dfef4fc70 r15505:306dfef4fc70 r27606:02acf14253b2 r15505:306dfef4fc70 r15505:306dfef4fc70 r15507:d6cc390ab191 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r10122:8be97f532491 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r25263:abcd2cc8e2ed r25263:abcd2cc8e2ed r24472:86d98d2f4c47 r13348:a18e66ad9ec7 r13348:a18e66ad9ec7 r24472:86d98d2f4c47 r10122:8be97f532491 r16074:92f60cf5758b r28287:89bc7cb52928 r26528:7330214f8231 r26528:7330214f8231 r28139:fb223258e802 r28224:bb1a33d7a0f2 r27606:02acf14253b2 r27606:02acf14253b2 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24473:6e405cbcc588 r24472:86d98d2f4c47 r10122:8be97f532491 r10122:8be97f532491 r13596:83142daf4c93 r13596:83142daf4c93 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r10122:8be97f532491 r24472:86d98d2f4c47 r24472:86d98d2f4c47 r10122:8be97f532491 r10122:8be97f532491 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file vehicle_gui_base.h Functions/classes shared between the different vehicle list GUIs. */
#ifndef VEHICLE_GUI_BASE_H
#define VEHICLE_GUI_BASE_H
#include "cargo_type.h"
#include "timer/timer_game_calendar.h"
#include "economy_type.h"
#include "sortlist_type.h"
#include "vehicle_base.h"
#include "vehiclelist.h"
#include "window_gui.h"
#include "widgets/dropdown_type.h"
typedef GUIList<const Vehicle*, std::nullptr_t, CargoID> GUIVehicleList;
struct GUIVehicleGroup {
VehicleList::const_iterator vehicles_begin; ///< Pointer to beginning element of this vehicle group.
VehicleList::const_iterator vehicles_end; ///< Pointer to past-the-end element of this vehicle group.
GUIVehicleGroup(VehicleList::const_iterator vehicles_begin, VehicleList::const_iterator vehicles_end)
: vehicles_begin(vehicles_begin), vehicles_end(vehicles_end) {}
std::ptrdiff_t NumVehicles() const
{
return std::distance(this->vehicles_begin, this->vehicles_end);
}
const Vehicle *GetSingleVehicle() const
{
assert(this->NumVehicles() == 1);
return this->vehicles_begin[0];
}
Money GetDisplayProfitThisYear() const
{
return std::accumulate(this->vehicles_begin, this->vehicles_end, (Money)0, [](Money acc, const Vehicle *v) {
return acc + v->GetDisplayProfitThisYear();
});
}
Money GetDisplayProfitLastYear() const
{
return std::accumulate(this->vehicles_begin, this->vehicles_end, (Money)0, [](Money acc, const Vehicle *v) {
return acc + v->GetDisplayProfitLastYear();
});
}
TimerGameCalendar::Date GetOldestVehicleAge() const
{
const Vehicle *oldest = *std::max_element(this->vehicles_begin, this->vehicles_end, [](const Vehicle *v_a, const Vehicle *v_b) {
return v_a->age < v_b->age;
});
return oldest->age;
}
};
typedef GUIList<GUIVehicleGroup, std::nullptr_t, CargoID> GUIVehicleGroupList;
struct BaseVehicleListWindow : public Window {
enum GroupBy : byte {
GB_NONE,
GB_SHARED_ORDERS,
GB_END,
};
GroupBy grouping; ///< How we want to group the list.
VehicleList vehicles; ///< List of vehicles. This is the buffer for `vehgroups` to point into; if this is structurally modified, `vehgroups` must be rebuilt.
GUIVehicleGroupList vehgroups; ///< List of (groups of) vehicles. This stores iterators of `vehicles`, and should be rebuilt if `vehicles` is structurally changed.
Listing *sorting; ///< Pointer to the vehicle type related sorting.
byte unitnumber_digits; ///< The number of digits of the highest unit number.
Scrollbar *vscroll;
VehicleListIdentifier vli; ///< Identifier of the vehicle list we want to currently show.
VehicleID vehicle_sel; ///< Selected vehicle
CargoID cargo_filter_criteria; ///< Selected cargo filter index
uint order_arrow_width; ///< Width of the arrow in the small order list.
CargoTypes used_cargoes;
typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
enum ActionDropdownItem {
ADI_REPLACE,
ADI_SERVICE,
ADI_DEPOT,
ADI_ADD_SHARED,
ADI_REMOVE_ALL,
ADI_CREATE_GROUP,
};
static const StringID vehicle_depot_name[];
static const StringID vehicle_group_by_names[];
static const StringID vehicle_group_none_sorter_names[];
static const StringID vehicle_group_shared_orders_sorter_names[];
static VehicleGroupSortFunction * const vehicle_group_none_sorter_funcs[];
static VehicleGroupSortFunction * const vehicle_group_shared_orders_sorter_funcs[];
BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno);
void OnInit() override;
void UpdateSortingFromGrouping();
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const;
void UpdateVehicleGroupBy(GroupBy group_by);
void SortVehicleList();
void BuildVehicleList();
void SetCargoFilter(byte index);
void SetCargoFilterArray();
void FilterVehicleList();
StringID GetCargoFilterLabel(CargoID cid) const;
DropDownList BuildCargoDropDownList(bool full) const;
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);
const StringID *GetVehicleSorterNames()
{
switch (this->grouping) {
case GB_NONE:
return vehicle_group_none_sorter_names;
case GB_SHARED_ORDERS:
return vehicle_group_shared_orders_sorter_names;
default:
NOT_REACHED();
}
}
VehicleGroupSortFunction * const *GetVehicleSorterFuncs()
{
switch (this->grouping) {
case GB_NONE:
return vehicle_group_none_sorter_funcs;
case GB_SHARED_ORDERS:
return vehicle_group_shared_orders_sorter_funcs;
default:
NOT_REACHED();
}
}
};
uint GetVehicleListHeight(VehicleType type, uint divisor = 1);
struct Sorting {
Listing aircraft;
Listing roadveh;
Listing ship;
Listing train;
};
extern BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
extern Sorting _sorting[BaseVehicleListWindow::GB_END];
#endif /* VEHICLE_GUI_BASE_H */
|