Merge branch 'master' into jgrpp
# Conflicts: # src/fileio.cpp # src/group_gui.cpp # src/industry.h # src/lang/korean.txt # src/linkgraph/linkgraphjob.cpp # src/linkgraph/linkgraphjob.h # src/linkgraph/linkgraphschedule.cpp # src/linkgraph/linkgraphschedule.h # src/openttd.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/town_cmd.cpp # src/vehicle_gui.cpp # src/vehicle_gui_base.h
This commit is contained in:
@@ -10,23 +10,62 @@
|
||||
#ifndef VEHICLE_GUI_BASE_H
|
||||
#define VEHICLE_GUI_BASE_H
|
||||
|
||||
#include "core/smallvec_type.hpp"
|
||||
#include "date_type.h"
|
||||
#include "economy_type.h"
|
||||
#include "sortlist_type.h"
|
||||
#include "vehiclelist.h"
|
||||
#include "window_gui.h"
|
||||
#include "widgets/dropdown_type.h"
|
||||
#include "cargo_type.h"
|
||||
#include <iterator>
|
||||
|
||||
typedef GUIList<const Vehicle*, 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.
|
||||
Money display_profit_this_year; ///< Total profit for the vehicle group this year.
|
||||
Money display_profit_last_year; ///< Total profit for the vehicle group laste year.
|
||||
Date age; ///< Age in days of oldest vehicle in the group.
|
||||
|
||||
GUIVehicleGroup(VehicleList::const_iterator vehicles_begin, VehicleList::const_iterator vehicles_end, Money display_profit_this_year, Money display_profit_last_year, Date age)
|
||||
: 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) {}
|
||||
|
||||
std::ptrdiff_t NumVehicles() const
|
||||
{
|
||||
return std::distance(vehicles_begin, vehicles_end);
|
||||
}
|
||||
const Vehicle *GetSingleVehicle() const
|
||||
{
|
||||
assert(NumVehicles() == 1);
|
||||
return vehicles_begin[0];
|
||||
}
|
||||
};
|
||||
|
||||
typedef GUIList<GUIVehicleGroup, CargoID> GUIVehicleGroupList;
|
||||
|
||||
struct BaseVehicleListWindow : public Window {
|
||||
GUIVehicleList vehicles; ///< The list of vehicles
|
||||
uint own_vehicles = 0; ///< Count of vehicles of the local company
|
||||
CompanyID own_company; ///< Company ID used for own_vehicles
|
||||
Listing *sorting; ///< Pointer to the vehicle type related sorting.
|
||||
byte unitnumber_digits; ///< The number of digits of the highest unit number
|
||||
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.
|
||||
uint own_vehicles = 0; ///< Count of vehicles of the local company
|
||||
CompanyID own_company; ///< Company ID used for own_vehicles
|
||||
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
|
||||
VehicleListIdentifier vli; ///< Identifier of the vehicle list we want to currently show.
|
||||
VehicleID vehicle_sel; ///< Selected vehicle
|
||||
|
||||
typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
|
||||
typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
|
||||
|
||||
/** Special cargo filter criteria */
|
||||
enum CargoFilterSpecialType {
|
||||
@@ -56,17 +95,21 @@ struct BaseVehicleListWindow : public Window {
|
||||
|
||||
static const StringID vehicle_depot_name[];
|
||||
static const StringID vehicle_depot_sell_name[];
|
||||
static const StringID vehicle_sorter_names[];
|
||||
static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[];
|
||||
|
||||
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[];
|
||||
|
||||
const uint vehicle_sorter_non_ground_veh_disable_mask = (1 << 11); // STR_SORT_BY_LENGTH
|
||||
|
||||
BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno))
|
||||
{
|
||||
this->vehicle_sel = INVALID_VEHICLE;
|
||||
this->vehicles.SetSortFuncs(this->vehicle_sorter_funcs);
|
||||
}
|
||||
BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno);
|
||||
|
||||
void UpdateSortingFromGrouping();
|
||||
|
||||
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const;
|
||||
void UpdateVehicleGroupBy(GroupBy group_by);
|
||||
void SortVehicleList();
|
||||
void CountOwnVehicles();
|
||||
void BuildVehicleList();
|
||||
@@ -79,6 +122,30 @@ struct BaseVehicleListWindow : public Window {
|
||||
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_template_replace,
|
||||
StringID change_order_str = 0, bool show_create_group = false, bool consider_top_level = false);
|
||||
bool ShouldShowActionDropdownList() const;
|
||||
|
||||
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);
|
||||
@@ -90,6 +157,7 @@ struct Sorting {
|
||||
Listing train;
|
||||
};
|
||||
|
||||
extern Sorting _sorting;
|
||||
extern BaseVehicleListWindow::GroupBy _grouping[VLT_END][VEH_COMPANY_END];
|
||||
extern Sorting _sorting[BaseVehicleListWindow::GB_END];
|
||||
|
||||
#endif /* VEHICLE_GUI_BASE_H */
|
||||
|
||||
Reference in New Issue
Block a user