1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-23 12:14:11 +01:00

Codechange: replace INVALID_X with XID::Invalid() for PoolIDs

This commit is contained in:
Rubidium
2025-02-16 19:29:53 +01:00
committed by rubidium42
parent d13b0e0813
commit fd4adc55e3
157 changed files with 744 additions and 772 deletions

View File

@@ -118,7 +118,7 @@ static constexpr NWidgetPart _nested_group_widgets[] = {
* @param parent Current tree parent (set by self with recursion).
* @param indent Current tree indentation level (set by self with recursion).
*/
static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent = INVALID_GROUP, uint8_t indent = 0)
static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent = GroupID::Invalid(), uint8_t indent = 0)
{
for (const auto &item : src) {
if (item.group->parent != parent) continue;
@@ -182,7 +182,7 @@ void BuildGuiGroupList(GUIGroupList &dst, bool fold, Owner owner, VehicleType ve
return r < 0;
});
GuiGroupListAddChildren(dst, list, fold, INVALID_GROUP, 0);
GuiGroupListAddChildren(dst, list, fold, GroupID::Invalid(), 0);
}
class VehicleGroupWindow : public BaseVehicleListWindow {
@@ -200,8 +200,8 @@ private:
};
GroupID group_sel; ///< Selected group (for drag/drop)
GroupID group_rename; ///< Group being renamed, INVALID_GROUP if none
GroupID group_over; ///< Group over which a vehicle is dragged, INVALID_GROUP if none
GroupID group_rename; ///< Group being renamed, GroupID::Invalid() if none
GroupID group_over; ///< Group over which a vehicle is dragged, GroupID::Invalid() if none
GroupID group_confirm; ///< Group awaiting delete confirmation
GUIGroupList groups; ///< List of groups
uint tiny_step_height; ///< Step height for the group list
@@ -374,7 +374,7 @@ private:
*/
void DirtyHighlightedGroupWidget()
{
if (this->group_over == INVALID_GROUP) return;
if (this->group_over == GroupID::Invalid()) return;
if (IsAllGroupID(this->group_over)) {
this->SetWidgetDirty(WID_GL_ALL_VEHICLES);
@@ -394,9 +394,9 @@ public:
this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR);
this->vli.SetIndex(ALL_GROUP);
this->group_sel = INVALID_GROUP;
this->group_rename = INVALID_GROUP;
this->group_over = INVALID_GROUP;
this->group_sel = GroupID::Invalid();
this->group_rename = GroupID::Invalid();
this->group_over = GroupID::Invalid();
this->groups.ForceRebuild();
this->groups.NeedResort();
@@ -496,9 +496,9 @@ public:
}
/* Process ID-invalidation in command-scope as well */
if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
if (this->group_rename != GroupID::Invalid() && !Group::IsValidID(this->group_rename)) {
CloseWindowByClass(WC_QUERY_STRING);
this->group_rename = INVALID_GROUP;
this->group_rename = GroupID::Invalid();
}
GroupID group = this->vli.ToGroupID();
@@ -757,7 +757,7 @@ public:
this->vli.SetIndex(g);
break;
}
} while (g != INVALID_GROUP);
} while (g != GroupID::Invalid());
}
Group::Get(it->group->index)->folded = !it->group->folded;
@@ -886,25 +886,25 @@ public:
switch (widget) {
case WID_GL_ALL_VEHICLES: // All vehicles
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
if (g->parent != INVALID_GROUP) {
Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, INVALID_GROUP, {});
if (g->parent != GroupID::Invalid()) {
Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, GroupID::Invalid(), {});
}
this->group_sel = INVALID_GROUP;
this->group_over = INVALID_GROUP;
this->group_sel = GroupID::Invalid();
this->group_over = GroupID::Invalid();
this->SetDirty();
break;
case WID_GL_LIST_GROUP: { // Matrix group
auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
GroupID new_g = it == this->groups.end() ? INVALID_GROUP : it->group->index;
GroupID new_g = it == this->groups.end() ? GroupID::Invalid() : it->group->index;
if (this->group_sel != new_g && g->parent != new_g) {
Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, new_g, {});
}
this->group_sel = INVALID_GROUP;
this->group_over = INVALID_GROUP;
this->group_sel = GroupID::Invalid();
this->group_over = GroupID::Invalid();
this->SetDirty();
break;
}
@@ -917,16 +917,16 @@ public:
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
Command<CMD_ADD_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, DEFAULT_GROUP, this->vehicle_sel, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{});
this->vehicle_sel = INVALID_VEHICLE;
this->group_over = INVALID_GROUP;
this->vehicle_sel = VehicleID::Invalid();
this->group_over = GroupID::Invalid();
this->SetDirty();
break;
case WID_GL_LIST_GROUP: { // Matrix group
const VehicleID vindex = this->vehicle_sel;
this->vehicle_sel = INVALID_VEHICLE;
this->group_over = INVALID_GROUP;
this->vehicle_sel = VehicleID::Invalid();
this->group_over = GroupID::Invalid();
this->SetDirty();
auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
@@ -938,8 +938,8 @@ public:
case WID_GL_LIST_VEHICLE: { // Matrix vehicle
const VehicleID vindex = this->vehicle_sel;
this->vehicle_sel = INVALID_VEHICLE;
this->group_over = INVALID_GROUP;
this->vehicle_sel = VehicleID::Invalid();
this->group_over = GroupID::Invalid();
this->SetDirty();
auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
@@ -979,16 +979,16 @@ public:
void OnDragDrop(Point pt, WidgetID widget) override
{
if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget);
if (this->vehicle_sel != VehicleID::Invalid()) OnDragDrop_Vehicle(pt, widget);
if (this->group_sel != GroupID::Invalid()) OnDragDrop_Group(pt, widget);
_cursor.vehchain = false;
}
void OnQueryTextFinished(std::optional<std::string> str) override
{
if (str.has_value()) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, INVALID_GROUP, *str);
this->group_rename = INVALID_GROUP;
if (str.has_value()) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, GroupID::Invalid(), *str);
this->group_rename = GroupID::Invalid();
}
void OnResize() override
@@ -1021,12 +1021,12 @@ public:
break;
case ADI_SERVICE: // Send for servicing
case ADI_DEPOT: { // Send to Depots
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli);
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), VehicleID::Invalid(), (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli);
break;
}
case ADI_CREATE_GROUP: // Create group
Command<CMD_ADD_VEHICLE_GROUP>::Post(CcAddVehicleNewGroup, NEW_GROUP, INVALID_VEHICLE, false, this->vli);
Command<CMD_ADD_VEHICLE_GROUP>::Post(CcAddVehicleNewGroup, NEW_GROUP, VehicleID::Invalid(), false, this->vli);
break;
case ADI_ADD_SHARED: // Add shared Vehicles
@@ -1059,19 +1059,19 @@ public:
void OnPlaceObjectAbort() override
{
/* abort drag & drop */
this->vehicle_sel = INVALID_VEHICLE;
this->vehicle_sel = VehicleID::Invalid();
this->DirtyHighlightedGroupWidget();
this->group_sel = INVALID_GROUP;
this->group_over = INVALID_GROUP;
this->group_sel = GroupID::Invalid();
this->group_over = GroupID::Invalid();
this->SetWidgetDirty(WID_GL_LIST_VEHICLE);
}
void OnMouseDrag(Point pt, WidgetID widget) override
{
if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return;
if (this->vehicle_sel == VehicleID::Invalid() && this->group_sel == GroupID::Invalid()) return;
/* A vehicle is dragged over... */
GroupID new_group_over = INVALID_GROUP;
GroupID new_group_over = GroupID::Invalid();
switch (widget) {
case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group.
new_group_over = DEFAULT_GROUP;
@@ -1085,10 +1085,10 @@ public:
}
/* Do not highlight when dragging over the current group */
if (this->vehicle_sel != INVALID_VEHICLE) {
if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = INVALID_GROUP;
} else if (this->group_sel != INVALID_GROUP) {
if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = INVALID_GROUP;
if (this->vehicle_sel != VehicleID::Invalid()) {
if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = GroupID::Invalid();
} else if (this->group_sel != GroupID::Invalid()) {
if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = GroupID::Invalid();
}
/* Mark widgets as dirty if the group changed. */
@@ -1128,7 +1128,7 @@ public:
*/
void SelectGroup(const GroupID g_id)
{
if (g_id == INVALID_GROUP || g_id == this->vli.ToGroupID()) return;
if (g_id == GroupID::Invalid() || g_id == this->vli.ToGroupID()) return;
this->vli.SetIndex(g_id);
if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
@@ -1184,7 +1184,7 @@ static WindowDesc _vehicle_group_desc[] = {
* Show the group window for the given company and vehicle type.
* @param company The company to show the window for.
* @param vehicle_type The type of vehicle to show it for.
* @param group The group to be selected. Defaults to INVALID_GROUP.
* @param group The group to be selected. Defaults to GroupID::Invalid().
* @tparam Tneed_existing_window Whether the existing window is needed.
*/
template <bool Tneed_existing_window>
@@ -1202,7 +1202,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type
* Show the group window for the given company and vehicle type.
* @param company The company to show the window for.
* @param vehicle_type The type of vehicle to show it for.
* @param group The group to be selected. Defaults to INVALID_GROUP.
* @param group The group to be selected. Defaults to GroupID::Invalid().
*/
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group)
{