1
0
Fork 0

Codechange: allow passing extra constructor arguments via AllocateWindowDescFront

pull/13445/head
Rubidium 2025-02-01 21:06:41 +01:00 committed by rubidium42
parent 8f72a478f0
commit e36a9ceaf0
4 changed files with 13 additions and 17 deletions

View File

@ -388,7 +388,7 @@ private:
} }
public: public:
VehicleGroupWindow(WindowDesc &desc, WindowNumber window_number) : BaseVehicleListWindow(desc, window_number) VehicleGroupWindow(WindowDesc &desc, WindowNumber window_number, const VehicleListIdentifier &vli) : BaseVehicleListWindow(desc, vli)
{ {
this->CreateNestedTree(); this->CreateNestedTree();
@ -1190,8 +1190,8 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
if (!Company::IsValidID(company)) return; if (!Company::IsValidID(company)) return;
assert(vehicle_type < std::size(_vehicle_group_desc)); assert(vehicle_type < std::size(_vehicle_group_desc));
const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack(); VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], num); VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.Pack(), vli);
if (w != nullptr) w->SelectGroup(group); if (w != nullptr) w->SelectGroup(group);
} }

View File

@ -162,7 +162,7 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
}; };
BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc &desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno)) BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc &desc, const VehicleListIdentifier &vli) : Window(desc), vli(vli)
{ {
this->vehicle_sel = INVALID_VEHICLE; this->vehicle_sel = INVALID_VEHICLE;
this->grouping = _grouping[vli.type][vli.vtype]; this->grouping = _grouping[vli.type][vli.vtype];
@ -1924,12 +1924,7 @@ void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
/** /**
* Window for the (old) vehicle listing. * Window for the (old) vehicle listing.
* * See #VehicleListIdentifier::Pack for the contents of the window number.
* bitmask for w->window_number
* 0-7 CompanyID (owner)
* 8-10 window type (use flags in vehicle_gui.h)
* 11-15 vehicle type (using VEH_, but can be compressed to fewer bytes if needed)
* 16-31 StationID or OrderID depending on window type (bit 8-10)
*/ */
struct VehicleListWindow : public BaseVehicleListWindow { struct VehicleListWindow : public BaseVehicleListWindow {
private: private:
@ -1946,7 +1941,7 @@ private:
}; };
public: public:
VehicleListWindow(WindowDesc &desc, WindowNumber window_number) : BaseVehicleListWindow(desc, window_number) VehicleListWindow(WindowDesc &desc, WindowNumber window_number, const VehicleListIdentifier &vli) : BaseVehicleListWindow(desc, vli)
{ {
this->CreateNestedTree(); this->CreateNestedTree();
@ -2332,8 +2327,8 @@ static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, V
if (!Company::IsValidID(company) && company != OWNER_NONE) return; if (!Company::IsValidID(company) && company != OWNER_NONE) return;
assert(vehicle_type < std::size(_vehicle_list_desc)); assert(vehicle_type < std::size(_vehicle_list_desc));
WindowNumber num = VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack(); VehicleListIdentifier vli(vlt, vehicle_type, company, unique_number);
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], num); AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], vli.Pack(), vli);
} }
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type) void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)

View File

@ -106,7 +106,7 @@ struct BaseVehicleListWindow : public Window {
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_none_sorter_funcs; static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_none_sorter_funcs;
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_shared_orders_sorter_funcs; static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_shared_orders_sorter_funcs;
BaseVehicleListWindow(WindowDesc &desc, WindowNumber wno); BaseVehicleListWindow(WindowDesc &desc, const VehicleListIdentifier &vli);
void OnInit() override; void OnInit() override;

View File

@ -1006,14 +1006,15 @@ Window *BringWindowToFrontById(WindowClass cls, ConvertibleThroughBase auto numb
* @tparam Treturn_existing If set, also return the window if it already existed. * @tparam Treturn_existing If set, also return the window if it already existed.
* @param desc The pointer to the WindowDesc to be created * @param desc The pointer to the WindowDesc to be created
* @param window_number the window number of the new window * @param window_number the window number of the new window
* @param extra_arguments optional extra arguments to pass to the window's constructor.
* @return %Window pointer of the newly created window, or the existing one if \a Treturn_existing is set, or \c nullptr. * @return %Window pointer of the newly created window, or the existing one if \a Treturn_existing is set, or \c nullptr.
*/ */
template <typename Twindow, bool Treturn_existing = false> template <typename Twindow, bool Treturn_existing = false, typename... Targs>
Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number) Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
{ {
Twindow *w = static_cast<Twindow *>(BringWindowToFrontById(desc.cls, window_number)); Twindow *w = static_cast<Twindow *>(BringWindowToFrontById(desc.cls, window_number));
if (w != nullptr) return Treturn_existing ? w : nullptr; if (w != nullptr) return Treturn_existing ? w : nullptr;
return new Twindow(desc, window_number); return new Twindow(desc, window_number, std::forward<Targs>(extra_arguments)...);
} }
void RelocateAllWindows(int neww, int newh); void RelocateAllWindows(int neww, int newh);