mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
Codechange: allow passing extra constructor arguments via AllocateWindowDescFront
This commit is contained in:
parent
8f72a478f0
commit
e36a9ceaf0
@ -388,7 +388,7 @@ private:
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@ -1190,8 +1190,8 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
|
||||
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, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], num);
|
||||
VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
|
||||
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.Pack(), vli);
|
||||
if (w != nullptr) w->SelectGroup(group);
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
|
||||
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->grouping = _grouping[vli.type][vli.vtype];
|
||||
@ -1924,12 +1924,7 @@ void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
|
||||
|
||||
/**
|
||||
* Window for the (old) vehicle listing.
|
||||
*
|
||||
* 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)
|
||||
* See #VehicleListIdentifier::Pack for the contents of the window number.
|
||||
*/
|
||||
struct VehicleListWindow : public BaseVehicleListWindow {
|
||||
private:
|
||||
@ -1946,7 +1941,7 @@ private:
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
@ -2332,8 +2327,8 @@ static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, V
|
||||
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();
|
||||
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], num);
|
||||
VehicleListIdentifier vli(vlt, vehicle_type, company, unique_number);
|
||||
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], vli.Pack(), vli);
|
||||
}
|
||||
|
||||
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)
|
||||
|
@ -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_shared_orders_sorter_funcs;
|
||||
|
||||
BaseVehicleListWindow(WindowDesc &desc, WindowNumber wno);
|
||||
BaseVehicleListWindow(WindowDesc &desc, const VehicleListIdentifier &vli);
|
||||
|
||||
void OnInit() override;
|
||||
|
||||
|
@ -1006,14 +1006,15 @@ Window *BringWindowToFrontById(WindowClass cls, ConvertibleThroughBase auto numb
|
||||
* @tparam Treturn_existing If set, also return the window if it already existed.
|
||||
* @param desc The pointer to the WindowDesc to be created
|
||||
* @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.
|
||||
*/
|
||||
template <typename Twindow, bool Treturn_existing = false>
|
||||
Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number)
|
||||
template <typename Twindow, bool Treturn_existing = false, typename... Targs>
|
||||
Twindow *AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
|
||||
{
|
||||
Twindow *w = static_cast<Twindow *>(BringWindowToFrontById(desc.cls, window_number));
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user