Implement adding a vehicle list to a new group.
This commit is contained in:
@@ -209,6 +209,7 @@ CommandProc CmdDepotMassAutoReplace;
|
||||
CommandProc CmdCreateGroup;
|
||||
CommandProc CmdAlterGroup;
|
||||
CommandProc CmdDeleteGroup;
|
||||
CommandProc CmdCreateGroupFromList;
|
||||
CommandProc CmdAddVehicleGroup;
|
||||
CommandProc CmdAddSharedVehicleGroup;
|
||||
CommandProc CmdRemoveAllVehiclesGroup;
|
||||
@@ -406,6 +407,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP
|
||||
DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP
|
||||
DEF_CMD(CmdAlterGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_ALTER_GROUP
|
||||
DEF_CMD(CmdCreateGroupFromList, 0, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_GROUP_FROM_LIST
|
||||
DEF_CMD(CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_VEHICLE_GROUP
|
||||
DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP
|
||||
DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP
|
||||
|
@@ -352,6 +352,7 @@ enum Commands {
|
||||
CMD_CREATE_GROUP, ///< create a new group
|
||||
CMD_DELETE_GROUP, ///< delete a group
|
||||
CMD_ALTER_GROUP, ///< alter a group
|
||||
CMD_CREATE_GROUP_FROM_LIST, ///< create and rename a new group from a vehicle list
|
||||
CMD_ADD_VEHICLE_GROUP, ///< add a vehicle to a group
|
||||
CMD_ADD_SHARED_VEHICLE_GROUP, ///< add all other shared vehicles to a group which are missing
|
||||
CMD_REMOVE_ALL_VEHICLES_GROUP, ///< remove all vehicles from a group
|
||||
|
@@ -427,6 +427,52 @@ CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new vehicle group.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 packed VehicleListIdentifier
|
||||
* @param p2 unused
|
||||
* @param text the new name or an empty string when setting to the default
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdCreateGroupFromList(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
VehicleListIdentifier vli;
|
||||
VehicleList list;
|
||||
if (!vli.Unpack(p1)) return CMD_ERROR;
|
||||
if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR;
|
||||
if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = DoCommand(tile, vli.vtype, 0, flags, CMD_CREATE_GROUP);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (!StrEmpty(text)) {
|
||||
if (Utf8StringLength(text) >= MAX_LENGTH_GROUP_NAME_CHARS) return CMD_ERROR;
|
||||
if (!IsUniqueGroupNameForVehicleType(text, vli.vtype)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Group *g = Group::GetIfValid(_new_group_id);
|
||||
if (g == NULL || g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
if (!StrEmpty(text)) {
|
||||
DoCommand(tile, g->index, 0, flags, CMD_ALTER_GROUP, text);
|
||||
}
|
||||
|
||||
for (uint i = 0; i < list.Length(); i++) {
|
||||
const Vehicle *v = list[i];
|
||||
|
||||
/* Just try and don't care if some vehicle's can't be added. */
|
||||
DoCommand(tile, g->index, v->index, flags, CMD_ADD_VEHICLE_GROUP);
|
||||
}
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do add a vehicle to a group.
|
||||
|
@@ -3799,6 +3799,8 @@ STR_VEHICLE_LIST_CHANGE_ORDER_ROAD_VEHICLE_DEPOT :Move order to a
|
||||
STR_VEHICLE_LIST_CHANGE_ORDER_SHIP_DEPOT :Move order to another depot
|
||||
STR_VEHICLE_LIST_CHANGE_ORDER_AIRCRAFT_HANGAR :Move order to another hangar
|
||||
|
||||
STR_VEHICLE_LIST_CREATE_GROUP :Create group from list
|
||||
|
||||
# Group window
|
||||
STR_GROUP_ALL_TRAINS :All trains
|
||||
STR_GROUP_ALL_ROAD_VEHICLES :All road vehicles
|
||||
|
@@ -171,6 +171,8 @@ Dimension BaseVehicleListWindow::GetActionDropdownSize(bool show_autoreplace, bo
|
||||
d = maxdim(d, GetStringBoundingBox(change_order_str));
|
||||
}
|
||||
|
||||
d = maxdim(d, GetStringBoundingBox(STR_VEHICLE_LIST_CREATE_GROUP));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -199,6 +201,8 @@ DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_autorepla
|
||||
*list->Append() = new DropDownListStringItem(change_order_str, ADI_CHANGE_ORDER, false);
|
||||
}
|
||||
|
||||
*list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_CREATE_GROUP, ADI_CREATE_GROUP, false);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -1792,6 +1796,10 @@ public:
|
||||
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT, this);
|
||||
break;
|
||||
|
||||
case ADI_CREATE_GROUP:
|
||||
ShowQueryString(STR_EMPTY, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -1800,6 +1808,11 @@ public:
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
DoCommandP(0, this->window_number, 0, CMD_CREATE_GROUP_FROM_LIST | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), NULL, str);
|
||||
}
|
||||
|
||||
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
||||
{
|
||||
/* check depot first */
|
||||
|
@@ -34,6 +34,7 @@ struct BaseVehicleListWindow : public Window {
|
||||
ADI_ADD_SHARED,
|
||||
ADI_REMOVE_ALL,
|
||||
ADI_CHANGE_ORDER,
|
||||
ADI_CREATE_GROUP,
|
||||
};
|
||||
|
||||
static const StringID vehicle_depot_name[];
|
||||
|
Reference in New Issue
Block a user