mirror of https://github.com/OpenTTD/OpenTTD
(svn r24139) -Add: Creating a new vehicle group by drag and drop. (Based on patch by Juanjo)
parent
0daf350922
commit
37e321044a
|
@ -91,6 +91,7 @@ CommandCallback CcGame;
|
||||||
|
|
||||||
/* group_gui.cpp */
|
/* group_gui.cpp */
|
||||||
CommandCallback CcCreateGroup;
|
CommandCallback CcCreateGroup;
|
||||||
|
CommandCallback CcAddVehicleNewGroup;
|
||||||
|
|
||||||
/* industry_gui.cpp */
|
/* industry_gui.cpp */
|
||||||
CommandCallback CcBuildIndustry;
|
CommandCallback CcBuildIndustry;
|
||||||
|
|
|
@ -429,7 +429,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
Vehicle *v = Vehicle::GetIfValid(GB(p2, 0, 20));
|
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) && new_g != NEW_GROUP)) return CMD_ERROR;
|
||||||
|
|
||||||
if (Group::IsValidID(new_g)) {
|
if (Group::IsValidID(new_g)) {
|
||||||
Group *g = Group::Get(new_g);
|
Group *g = Group::Get(new_g);
|
||||||
|
@ -438,6 +438,14 @@ 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 (new_g == NEW_GROUP) {
|
||||||
|
/* Create new group. */
|
||||||
|
CommandCost ret = CmdCreateGroup(0, flags, v->type, 0, NULL);
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
|
new_g = _new_group_id;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
AddVehicleToGroup(v, new_g);
|
AddVehicleToGroup(v, new_g);
|
||||||
|
|
||||||
|
|
|
@ -646,9 +646,9 @@ public:
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
|
||||||
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;
|
GroupID new_g = id_g >= this->groups.Length() ? NEW_GROUP : this->groups[id_g]->index;
|
||||||
|
|
||||||
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));
|
DoCommandP(0, new_g, vindex | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,6 +864,21 @@ void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32
|
||||||
if (w != NULL) w->ShowRenameGroupWindow(_new_group_id, true);
|
if (w != NULL) w->ShowRenameGroupWindow(_new_group_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open rename window after adding a vehicle to a new group via drag and drop.
|
||||||
|
* @param success Did command succeed?
|
||||||
|
* @param tile Unused.
|
||||||
|
* @param p1 Unused.
|
||||||
|
* @param p2 Bit 0-19: Vehicle ID.
|
||||||
|
*/
|
||||||
|
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||||
|
{
|
||||||
|
if (result.Failed()) return;
|
||||||
|
assert(Vehicle::IsValidID(GB(p2, 0, 20)));
|
||||||
|
|
||||||
|
CcCreateGroup(result, 0, Vehicle::Get(GB(p2, 0, 20))->type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the highlight of a vehicle in a group window
|
* Removes the highlight of a vehicle in a group window
|
||||||
* @param *v Vehicle to remove all highlights from
|
* @param *v Vehicle to remove all highlights from
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
typedef uint16 GroupID; ///< Type for all group identifiers.
|
typedef uint16 GroupID; ///< Type for all group identifiers.
|
||||||
|
|
||||||
|
static const GroupID NEW_GROUP = 0xFFFC; ///< Sentinel for a to-be-created group.
|
||||||
static const GroupID ALL_GROUP = 0xFFFD; ///< All vehicles are in this group.
|
static const GroupID ALL_GROUP = 0xFFFD; ///< All vehicles are in this group.
|
||||||
static const GroupID DEFAULT_GROUP = 0xFFFE; ///< Ungrouped vehicles are in this group.
|
static const GroupID DEFAULT_GROUP = 0xFFFE; ///< Ungrouped vehicles are in this group.
|
||||||
static const GroupID INVALID_GROUP = 0xFFFF; ///< Sentinel for invalid groups.
|
static const GroupID INVALID_GROUP = 0xFFFF; ///< Sentinel for invalid groups.
|
||||||
|
|
|
@ -48,6 +48,7 @@ static CommandCallback * const _callback_table[] = {
|
||||||
/* 0x18 */ CcBuildIndustry,
|
/* 0x18 */ CcBuildIndustry,
|
||||||
/* 0x19 */ CcStartStopVehicle,
|
/* 0x19 */ CcStartStopVehicle,
|
||||||
/* 0x1A */ CcGame,
|
/* 0x1A */ CcGame,
|
||||||
|
/* 0x1B */ CcAddVehicleNewGroup,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue