mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r24138) -Feature(ette): Ctrl+drag to add all vehicles with a shared order list to a group. (Juanjo)
This commit is contained in:
parent
e44a923a71
commit
0daf350922
@ -386,6 +386,32 @@ CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do add a vehicle to a group.
|
||||||
|
* @param v Vehicle to add.
|
||||||
|
* @param new_g Group to add to.
|
||||||
|
*/
|
||||||
|
static void AddVehicleToGroup(Vehicle *v, GroupID new_g)
|
||||||
|
{
|
||||||
|
GroupStatistics::CountVehicle(v, -1);
|
||||||
|
|
||||||
|
switch (v->type) {
|
||||||
|
default: NOT_REACHED();
|
||||||
|
case VEH_TRAIN:
|
||||||
|
SetTrainGroupID(Train::From(v), new_g);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VEH_ROAD:
|
||||||
|
case VEH_SHIP:
|
||||||
|
case VEH_AIRCRAFT:
|
||||||
|
if (v->IsEngineCountable()) UpdateNumEngineGroup(v, v->group_id, new_g);
|
||||||
|
v->group_id = new_g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupStatistics::CountVehicle(v, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a vehicle to a group
|
* Add a vehicle to a group
|
||||||
* @param tile unused
|
* @param tile unused
|
||||||
@ -394,12 +420,13 @@ CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
* - p1 bit 0-15 : GroupID
|
* - p1 bit 0-15 : GroupID
|
||||||
* @param p2 vehicle to add to a group
|
* @param p2 vehicle to add to a group
|
||||||
* - p2 bit 0-19 : VehicleID
|
* - p2 bit 0-19 : VehicleID
|
||||||
|
* - p2 bit 31 : Add shared vehicles as well.
|
||||||
* @param text unused
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
*/
|
*/
|
||||||
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Vehicle *v = Vehicle::GetIfValid(p2);
|
Vehicle *v = Vehicle::GetIfValid(GB(p2, 0, 20));
|
||||||
GroupID new_g = p1;
|
GroupID new_g = p1;
|
||||||
|
|
||||||
if (v == NULL || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
|
if (v == NULL || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
|
||||||
@ -412,22 +439,15 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
if (v->owner != _current_company || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v->owner != _current_company || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
GroupStatistics::CountVehicle(v, -1);
|
AddVehicleToGroup(v, new_g);
|
||||||
|
|
||||||
switch (v->type) {
|
if (HasBit(p2, 31)) {
|
||||||
default: NOT_REACHED();
|
/* Add vehicles in the shared order list as well. */
|
||||||
case VEH_TRAIN:
|
for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) {
|
||||||
SetTrainGroupID(Train::From(v), new_g);
|
if (v2->group_id != new_g) AddVehicleToGroup(v2, new_g);
|
||||||
break;
|
}
|
||||||
case VEH_ROAD:
|
|
||||||
case VEH_SHIP:
|
|
||||||
case VEH_AIRCRAFT:
|
|
||||||
if (v->IsEngineCountable()) UpdateNumEngineGroup(v, v->group_id, new_g);
|
|
||||||
v->group_id = new_g;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupStatistics::CountVehicle(v, 1);
|
|
||||||
GroupStatistics::UpdateAutoreplace(v->owner);
|
GroupStatistics::UpdateAutoreplace(v->owner);
|
||||||
|
|
||||||
/* Update the Replace Vehicle Windows */
|
/* Update the Replace Vehicle Windows */
|
||||||
|
@ -631,7 +631,7 @@ public:
|
|||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_GL_ALL_VEHICLES: // All vehicles
|
case WID_GL_ALL_VEHICLES: // All vehicles
|
||||||
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
|
case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
|
||||||
DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
|
DoCommandP(0, DEFAULT_GROUP, this->vehicle_sel | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
|
||||||
|
|
||||||
this->vehicle_sel = INVALID_VEHICLE;
|
this->vehicle_sel = INVALID_VEHICLE;
|
||||||
this->group_over = INVALID_GROUP;
|
this->group_over = INVALID_GROUP;
|
||||||
@ -648,7 +648,7 @@ public:
|
|||||||
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
|
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
|
||||||
if (id_g >= this->groups.Length()) return;
|
if (id_g >= this->groups.Length()) return;
|
||||||
|
|
||||||
DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
|
DoCommandP(0, this->groups[id_g]->index, vindex | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user