1
0
Fork 0

Codechange: ToWindowNumber describes better what is the intent than Pack

pull/13445/head
Rubidium 2025-02-01 21:15:26 +01:00 committed by rubidium42
parent 6b7cb4ede3
commit 5a78bb8fac
13 changed files with 31 additions and 30 deletions

View File

@ -842,7 +842,7 @@ CommandCost CmdSetAutoReplace(DoCommandFlag flags, GroupID id_g, EngineID old_en
if (IsLocalCompany()) SetWindowDirty(WC_REPLACE_VEHICLE, Engine::Get(old_engine_type)->type);
const VehicleType vt = Engine::Get(old_engine_type)->type;
SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack());
SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber());
}
if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g);

View File

@ -45,5 +45,5 @@ Depot::~Depot()
/* Delete the depot list */
VehicleType vt = GetDepotVehicleType(this->xy);
CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack());
CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).ToWindowNumber());
}

View File

@ -72,7 +72,7 @@ CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::str
/* Update the depot list */
VehicleType vt = GetDepotVehicleType(d->xy);
SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack());
SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).ToWindowNumber());
}
return CommandCost();
}

View File

@ -299,7 +299,7 @@ struct DepotWindow : Window {
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(WC_BUILD_VEHICLE, this->window_number);
CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDepotIndex()).Pack(), false);
CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDepotIndex()).ToWindowNumber(), false);
OrderBackup::Reset(TileIndex(this->window_number));
this->Window::Close();
}

View File

@ -363,7 +363,7 @@ std::tuple<CommandCost, GroupID> CmdCreateGroup(DoCommandFlag flags, VehicleType
g->flags = pg->flags;
}
InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber());
InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type);
return { CommandCost(), g->index };
@ -415,7 +415,7 @@ CommandCost CmdDeleteGroup(DoCommandFlag flags, GroupID group_id)
CloseWindowById(WC_REPLACE_VEHICLE, g->vehicle_type);
delete g;
InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber());
InvalidateWindowData(WC_COMPANY_COLOUR, _current_company, vt);
}
@ -485,7 +485,7 @@ CommandCost CmdAlterGroup(DoCommandFlag flags, AlterGroupMode mode, GroupID grou
if (flags & DC_EXEC) {
InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type, 1);
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber());
InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type);
InvalidateWindowClassesData(WC_VEHICLE_VIEW);
InvalidateWindowClassesData(WC_VEHICLE_DETAILS);
@ -590,7 +590,7 @@ std::tuple<CommandCost, GroupID> CmdAddVehicleGroup(DoCommandFlag flags, GroupID
/* Update the Replace Vehicle Windows */
SetWindowDirty(WC_REPLACE_VEHICLE, vtype);
InvalidateWindowData(GetWindowClassForVehicleType(vtype), VehicleListIdentifier(VL_GROUP_LIST, vtype, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(vtype), VehicleListIdentifier(VL_GROUP_LIST, vtype, _current_company).ToWindowNumber());
}
return { CommandCost(), new_g };
@ -621,7 +621,7 @@ CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, GroupID id_g, VehicleT
}
}
InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).ToWindowNumber());
}
return CommandCost();
@ -651,7 +651,7 @@ CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlag flags, GroupID group_id)
}
}
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack());
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber());
}
return CommandCost();
@ -729,7 +729,7 @@ CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlag fla
if (flags & DC_EXEC) {
SetGroupFlag(g, flag, value, recursive);
SetWindowDirty(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack());
SetWindowDirty(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber());
InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type);
}

View File

@ -1191,7 +1191,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
assert(vehicle_type < std::size(_vehicle_group_desc));
VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company);
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.Pack(), vli);
VehicleGroupWindow *w = AllocateWindowDescFront<VehicleGroupWindow, Tneed_existing_window>(_vehicle_group_desc[vehicle_type], vli.ToWindowNumber(), vli);
if (w != nullptr) w->SelectGroup(group);
}
@ -1223,7 +1223,7 @@ void ShowCompanyGroupForVehicle(const Vehicle *v)
*/
static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner)
{
return dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack()));
return dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).ToWindowNumber()));
}
/**

View File

@ -52,10 +52,10 @@ BaseStation::~BaseStation()
{
if (CleaningPool()) return;
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).ToWindowNumber());
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).ToWindowNumber());
this->sign.MarkDirty();
}

View File

@ -1375,10 +1375,10 @@ struct StationViewWindow : public Window {
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).ToWindowNumber(), false);
CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).ToWindowNumber(), false);
SetViewportCatchmentStation(Station::Get(this->window_number), false);
this->Window::Close();

View File

@ -3005,12 +3005,12 @@ void Vehicle::RemoveFromShared()
if (this->orders->GetNumVehicles() == 1) {
/* When there is only one vehicle, remove the shared order list window. */
CloseWindowById(GetWindowClassForVehicleType(this->type), vli.Pack());
CloseWindowById(GetWindowClassForVehicleType(this->type), vli.ToWindowNumber());
InvalidateVehicleOrder(this->FirstShared(), VIWD_MODIFY_ORDERS);
} else if (were_first) {
/* If we were the first one, update to the new first one.
* Note: FirstShared() is already the new first */
InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31));
InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.ToWindowNumber(), this->FirstShared()->index | (1U << 31));
}
this->next_shared = nullptr;

View File

@ -2281,7 +2281,7 @@ public:
if (!gui_scope && HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) {
/* Needs to be done in command-scope, so everything stays valid */
this->vli.index = GB(data, 0, 20);
this->window_number = this->vli.Pack();
this->window_number = this->vli.ToWindowNumber();
this->vehgroups.ForceRebuild();
return;
}
@ -2328,7 +2328,7 @@ static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, V
assert(vehicle_type < std::size(_vehicle_list_desc));
VehicleListIdentifier vli(vlt, vehicle_type, company, unique_number);
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], vli.Pack(), vli);
AllocateWindowDescFront<VehicleListWindow>(_vehicle_list_desc[vehicle_type], vli.ToWindowNumber(), vli);
}
void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type)

View File

@ -17,10 +17,10 @@
#include "safeguards.h"
/**
* Pack a VehicleListIdentifier in a single uint32.
* @return The packed identifier.
* Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber.
* @return The window number.
*/
uint32_t VehicleListIdentifier::Pack() const
WindowNumber VehicleListIdentifier::ToWindowNumber() const
{
uint8_t c = this->company == OWNER_NONE ? 0xF : (uint8_t)this->company;
assert(c < (1 << 4));

View File

@ -13,6 +13,7 @@
#include "vehicle_type.h"
#include "company_type.h"
#include "tile_type.h"
#include "window_type.h"
/** Vehicle List type flags */
enum VehicleListType : uint8_t {
@ -31,7 +32,7 @@ struct VehicleListIdentifier {
CompanyID company; ///< The company associated with this list.
uint32_t index; ///< A vehicle list type specific index.
uint32_t Pack() const;
WindowNumber ToWindowNumber() const;
bool Valid() const { return this->type < VLT_END; }

View File

@ -104,7 +104,7 @@ public:
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, this->owner, this->window_number).Pack(), false);
CloseWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, this->owner, this->window_number).ToWindowNumber(), false);
SetViewportCatchmentWaypoint(Waypoint::Get(this->window_number), false);
this->Window::Close();
}