1
0
Fork 0

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
Peter Nelson 2024-11-07 12:16:28 +00:00 committed by Peter Nelson
parent 6c9b3f17b7
commit 95df7ea483
2 changed files with 56 additions and 40 deletions

View File

@ -1150,20 +1150,32 @@ public:
};
static WindowDesc _other_group_desc(
WDP_AUTO, "list_groups", 460, 246,
WC_INVALID, WC_NONE,
0,
_nested_group_widgets
);
static WindowDesc _train_group_desc(
WDP_AUTO, "list_groups_train", 525, 246,
WC_TRAINS_LIST, WC_NONE,
0,
_nested_group_widgets
);
static WindowDesc _vehicle_group_desc[] = {
{
WDP_AUTO, "list_groups_train", 525, 246,
WC_TRAINS_LIST, WC_NONE,
0,
_nested_group_widgets
},
{
WDP_AUTO, "list_groups_roadveh", 460, 246,
WC_ROADVEH_LIST, WC_NONE,
0,
_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.
@ -1176,14 +1188,9 @@ void ShowCompanyGroup(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;
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);
}
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow>(_vehicle_group_desc[vehicle_type], num, need_existing_window);
if (w != nullptr) w->SelectGroup(group);
}

View File

@ -2300,31 +2300,40 @@ public:
}
};
static WindowDesc _vehicle_list_other_desc(
WDP_AUTO, "list_vehicles", 260, 246,
WC_INVALID, WC_NONE,
0,
_nested_vehicle_list
);
static WindowDesc _vehicle_list_train_desc(
WDP_AUTO, "list_vehicles_train", 325, 246,
WC_TRAINS_LIST, WC_NONE,
0,
_nested_vehicle_list
);
static WindowDesc _vehicle_list_desc[] = {
{
WDP_AUTO, "list_vehicles_train", 325, 246,
WC_TRAINS_LIST, WC_NONE,
0,
_nested_vehicle_list
},
{
WDP_AUTO, "list_vehicles_roadveh", 260, 246,
WC_INVALID, WC_NONE,
0,
_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)
{
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();
if (vehicle_type == VEH_TRAIN) {
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_train_desc, num);
} else {
_vehicle_list_other_desc.cls = GetWindowClassForVehicleType(vehicle_type);
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_other_desc, num);
}
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], num);
}
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)