mirror of https://github.com/OpenTTD/OpenTTD
Change: Use separate WindowDescs instead of changing static data.
When opening vehicle lists a static WindowDesc is modified to change the class depending on the vehicle type. Theses makes for inconsistencies and preferred window state, and prevents WindowDesc members being made const.pull/13377/head
parent
6c9b3f17b7
commit
95df7ea483
|
@ -1150,20 +1150,32 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static WindowDesc _vehicle_group_desc[] = {
|
||||||
static WindowDesc _other_group_desc(
|
{
|
||||||
WDP_AUTO, "list_groups", 460, 246,
|
WDP_AUTO, "list_groups_train", 525, 246,
|
||||||
WC_INVALID, WC_NONE,
|
WC_TRAINS_LIST, WC_NONE,
|
||||||
0,
|
0,
|
||||||
_nested_group_widgets
|
_nested_group_widgets
|
||||||
);
|
},
|
||||||
|
{
|
||||||
static WindowDesc _train_group_desc(
|
WDP_AUTO, "list_groups_roadveh", 460, 246,
|
||||||
WDP_AUTO, "list_groups_train", 525, 246,
|
WC_ROADVEH_LIST, WC_NONE,
|
||||||
WC_TRAINS_LIST, WC_NONE,
|
0,
|
||||||
0,
|
_nested_group_widgets
|
||||||
_nested_group_widgets
|
},
|
||||||
);
|
{
|
||||||
|
WDP_AUTO, "list_groups_ship", 460, 246,
|
||||||
|
WC_SHIPS_LIST, WC_NONE,
|
||||||
|
0,
|
||||||
|
_nested_group_widgets
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WDP_AUTO, "list_groups_aircraft", 460, 246,
|
||||||
|
WC_AIRCRAFT_LIST, WC_NONE,
|
||||||
|
0,
|
||||||
|
_nested_group_widgets
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the group window for the given company and vehicle type.
|
* Show the group window for the given company and vehicle type.
|
||||||
|
@ -1176,14 +1188,9 @@ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group
|
||||||
{
|
{
|
||||||
if (!Company::IsValidID(company)) return;
|
if (!Company::IsValidID(company)) return;
|
||||||
|
|
||||||
|
assert(vehicle_type < std::size(_vehicle_group_desc));
|
||||||
const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
|
const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack();
|
||||||
VehicleGroupWindow *w;
|
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow>(_vehicle_group_desc[vehicle_type], num, need_existing_window);
|
||||||
if (vehicle_type == VEH_TRAIN) {
|
|
||||||
w = AllocateWindowDescFront<VehicleGroupWindow>(_train_group_desc, num, need_existing_window);
|
|
||||||
} else {
|
|
||||||
_other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
|
|
||||||
w = AllocateWindowDescFront<VehicleGroupWindow>(_other_group_desc, num, need_existing_window);
|
|
||||||
}
|
|
||||||
if (w != nullptr) w->SelectGroup(group);
|
if (w != nullptr) w->SelectGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2300,31 +2300,40 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static WindowDesc _vehicle_list_other_desc(
|
static WindowDesc _vehicle_list_desc[] = {
|
||||||
WDP_AUTO, "list_vehicles", 260, 246,
|
{
|
||||||
WC_INVALID, WC_NONE,
|
WDP_AUTO, "list_vehicles_train", 325, 246,
|
||||||
0,
|
WC_TRAINS_LIST, WC_NONE,
|
||||||
_nested_vehicle_list
|
0,
|
||||||
);
|
_nested_vehicle_list
|
||||||
|
},
|
||||||
static WindowDesc _vehicle_list_train_desc(
|
{
|
||||||
WDP_AUTO, "list_vehicles_train", 325, 246,
|
WDP_AUTO, "list_vehicles_roadveh", 260, 246,
|
||||||
WC_TRAINS_LIST, WC_NONE,
|
WC_INVALID, WC_NONE,
|
||||||
0,
|
0,
|
||||||
_nested_vehicle_list
|
_nested_vehicle_list
|
||||||
);
|
},
|
||||||
|
{
|
||||||
|
WDP_AUTO, "list_vehicles_ship", 260, 246,
|
||||||
|
WC_INVALID, WC_NONE,
|
||||||
|
0,
|
||||||
|
_nested_vehicle_list
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WDP_AUTO, "list_vehicles_aircraft", 260, 246,
|
||||||
|
WC_INVALID, WC_NONE,
|
||||||
|
0,
|
||||||
|
_nested_vehicle_list
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32_t unique_number)
|
static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32_t unique_number)
|
||||||
{
|
{
|
||||||
if (!Company::IsValidID(company) && company != OWNER_NONE) return;
|
if (!Company::IsValidID(company) && company != OWNER_NONE) return;
|
||||||
|
|
||||||
|
assert(vehicle_type < std::size(_vehicle_list_desc));
|
||||||
WindowNumber num = VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack();
|
WindowNumber num = VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack();
|
||||||
if (vehicle_type == VEH_TRAIN) {
|
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], num);
|
||||||
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_train_desc, num);
|
|
||||||
} else {
|
|
||||||
_vehicle_list_other_desc.cls = GetWindowClassForVehicleType(vehicle_type);
|
|
||||||
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_other_desc, num);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)
|
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)
|
||||||
|
|
Loading…
Reference in New Issue