From 95df7ea4833eb10241645f757184535918f5729d Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 7 Nov 2024 12:16:28 +0000 Subject: [PATCH] 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. --- src/group_gui.cpp | 49 ++++++++++++++++++++++++++------------------- src/vehicle_gui.cpp | 47 +++++++++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/group_gui.cpp b/src/group_gui.cpp index a0f9ac7c13..9f813db8ad 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -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(_train_group_desc, num, need_existing_window); - } else { - _other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type); - w = AllocateWindowDescFront(_other_group_desc, num, need_existing_window); - } + VehicleGroupWindow *w = AllocateWindowDescFront(_vehicle_group_desc[vehicle_type], num, need_existing_window); if (w != nullptr) w->SelectGroup(group); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index c0d06f7a4b..e95b0b914e 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -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(_vehicle_list_train_desc, num); - } else { - _vehicle_list_other_desc.cls = GetWindowClassForVehicleType(vehicle_type); - AllocateWindowDescFront(_vehicle_list_other_desc, num); - } + AllocateWindowDescFront(_vehicle_list_desc[vehicle_type], num); } void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)