1
0
Fork 0

Add: filter for "engines only" in build train window (#8733)

pull/8819/head
Didac Perez Parera 2021-03-08 03:03:11 -08:00 committed by GitHub
parent f70aa8fabe
commit 6e2a96c133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 13 deletions

View File

@ -86,8 +86,9 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = {
}; };
/** Special cargo filter criteria */ /** Special cargo filter criteria */
static const CargoID CF_ANY = CT_NO_REFIT; ///< Show all vehicles independent of carried cargo (i.e. no filtering) static const CargoID CF_ANY = CT_NO_REFIT; ///< Show all vehicles independent of carried cargo (i.e. no filtering)
static const CargoID CF_NONE = CT_INVALID; ///< Show only vehicles which do not carry cargo (e.g. train engines) static const CargoID CF_NONE = CT_INVALID; ///< Show only vehicles which do not carry cargo (e.g. train engines)
static const CargoID CF_ENGINES = CT_AUTO_REFIT; ///< Show only engines (for rail vehicles only)
bool _engine_sort_direction; ///< \c false = descending, \c true = ascending. bool _engine_sort_direction; ///< \c false = descending, \c true = ascending.
byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type. byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Last set sort criteria, for each vehicle type.
@ -531,16 +532,21 @@ const StringID _engine_sort_listing[][12] = {{
INVALID_STRING_ID INVALID_STRING_ID
}}; }};
/** Cargo filter functions */ /** Filters vehicles by cargo and engine (in case of rail vehicle). */
static bool CDECL CargoFilter(const EngineID *eid, const CargoID cid) static bool CDECL CargoAndEngineFilter(const EngineID *eid, const CargoID cid)
{ {
if (cid == CF_ANY) return true; if (cid == CF_ANY) {
CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(*eid, true) & _standard_cargo_mask; return true;
return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid)); } else if (cid == CF_ENGINES) {
return Engine::Get(*eid)->GetPower() != 0;
} else {
CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(*eid, true) & _standard_cargo_mask;
return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
}
} }
static GUIEngineList::FilterFunction * const _filter_funcs[] = { static GUIEngineList::FilterFunction * const _filter_funcs[] = {
&CargoFilter, &CargoAndEngineFilter,
}; };
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te) static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te)
@ -1046,8 +1052,8 @@ struct BuildVehicleWindow : Window {
EngineID sel_engine; ///< Currently selected engine, or #INVALID_ENGINE EngineID sel_engine; ///< Currently selected engine, or #INVALID_ENGINE
EngineID rename_engine; ///< Engine being renamed. EngineID rename_engine; ///< Engine being renamed.
GUIEngineList eng_list; GUIEngineList eng_list;
CargoID cargo_filter[NUM_CARGO + 2]; ///< Available cargo filters; CargoID or CF_ANY or CF_NONE CargoID cargo_filter[NUM_CARGO + 3]; ///< Available cargo filters; CargoID or CF_ANY or CF_NONE or CF_ENGINES
StringID cargo_filter_texts[NUM_CARGO + 3]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID StringID cargo_filter_texts[NUM_CARGO + 4]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
byte cargo_filter_criteria; ///< Selected cargo filter byte cargo_filter_criteria; ///< Selected cargo filter
int details_height; ///< Minimal needed height of the details panels (found so far). int details_height; ///< Minimal needed height of the details panels (found so far).
Scrollbar *vscroll; Scrollbar *vscroll;
@ -1165,9 +1171,15 @@ struct BuildVehicleWindow : Window {
this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES; this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
filter_items++; filter_items++;
/* Add item for vehicles not carrying anything, e.g. train engines. /* Specific filters for trains. */
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
if (this->vehicle_type == VEH_TRAIN) { if (this->vehicle_type == VEH_TRAIN) {
/* Add item for locomotives only in case of trains. */
this->cargo_filter[filter_items] = CF_ENGINES;
this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ENGINES_ONLY;
filter_items++;
/* Add item for vehicles not carrying anything, e.g. train engines.
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
this->cargo_filter[filter_items] = CF_NONE; this->cargo_filter[filter_items] = CF_NONE;
this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_NONE; this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_NONE;
filter_items++; filter_items++;
@ -1254,7 +1266,7 @@ struct BuildVehicleWindow : Window {
bool FilterSingleEngine(EngineID eid) bool FilterSingleEngine(EngineID eid)
{ {
CargoID filter_type = this->cargo_filter[this->cargo_filter_criteria]; CargoID filter_type = this->cargo_filter[this->cargo_filter_criteria];
return (filter_type == CF_ANY || CargoFilter(&eid, filter_type)); return CargoAndEngineFilter(&eid, filter_type);
} }
/* Figure out what train EngineIDs to put in the list */ /* Figure out what train EngineIDs to put in the list */

View File

@ -3566,6 +3566,7 @@ STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Powered
STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}{STRING2} STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Refittable to: {GOLD}{STRING2}
STR_PURCHASE_INFO_ALL_TYPES :All cargo types STR_PURCHASE_INFO_ALL_TYPES :All cargo types
STR_PURCHASE_INFO_NONE :None STR_PURCHASE_INFO_NONE :None
STR_PURCHASE_INFO_ENGINES_ONLY :Engines only
STR_PURCHASE_INFO_ALL_BUT :All but {CARGO_LIST} STR_PURCHASE_INFO_ALL_BUT :All but {CARGO_LIST}
STR_PURCHASE_INFO_MAX_TE :{BLACK}Max. Tractive Effort: {GOLD}{FORCE} STR_PURCHASE_INFO_MAX_TE :{BLACK}Max. Tractive Effort: {GOLD}{FORCE}
STR_PURCHASE_INFO_AIRCRAFT_RANGE :{BLACK}Range: {GOLD}{COMMA} tiles STR_PURCHASE_INFO_AIRCRAFT_RANGE :{BLACK}Range: {GOLD}{COMMA} tiles