mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-21 19:32:54 +01:00
Codechange: change 'return existing window' to a template parameter
This change is made to make it possible to pass arbitrary other parameters to the constructor of the window instances.
This commit is contained in:
@@ -1182,25 +1182,37 @@ static WindowDesc _vehicle_group_desc[] = {
|
||||
* @param company The company to show the window for.
|
||||
* @param vehicle_type The type of vehicle to show it for.
|
||||
* @param group The group to be selected. Defaults to INVALID_GROUP.
|
||||
* @param need_existing_window Whether the existing window is needed. Defaults to false.
|
||||
* @tparam Tneed_existing_window Whether the existing window is needed.
|
||||
*/
|
||||
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group, bool need_existing_window)
|
||||
template <bool Tneed_existing_window>
|
||||
static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type, GroupID group)
|
||||
{
|
||||
if (!Company::IsValidID(company)) return;
|
||||
|
||||
assert(vehicle_type < std::size(_vehicle_group_desc));
|
||||
const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
|
||||
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow>(_vehicle_group_desc[vehicle_type], num, need_existing_window);
|
||||
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], num);
|
||||
if (w != nullptr) w->SelectGroup(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the group window for the given company and vehicle type.
|
||||
* @param company The company to show the window for.
|
||||
* @param vehicle_type The type of vehicle to show it for.
|
||||
* @param group The group to be selected. Defaults to INVALID_GROUP.
|
||||
*/
|
||||
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group)
|
||||
{
|
||||
ShowCompanyGroupInternal<false>(company, vehicle_type, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the group window for the given vehicle.
|
||||
* @param v The vehicle to show the window for.
|
||||
*/
|
||||
void ShowCompanyGroupForVehicle(const Vehicle *v)
|
||||
{
|
||||
ShowCompanyGroup(v->owner, v->type, v->group_id, true);
|
||||
ShowCompanyGroupInternal<true>(v->owner, v->type, v->group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user