(svn r17281) -Feature(tte): open the 'Rename group' dialog after creating new group

pull/155/head
smatz 15 years ago
parent 87d32250da
commit 1c6a2d72e2

@ -61,6 +61,9 @@ CommandCallback CcBuildShip;
CommandCallback CcBuildWagon;
CommandCallback CcBuildLoco;
/* group_gui.cpp */
CommandCallback CcCreateGroup;
/* ai/ai_core.cpp */
CommandCallback CcAI;
@ -89,6 +92,7 @@ CommandCallback *_callback_table[] = {
/* 0x15 */ CcAI,
/* 0x16 */ CcCloneVehicle,
/* 0x17 */ CcGiveMoney,
/* 0x18 */ CcCreateGroup,
};
const int _callback_table_count = lengthof(_callback_table);

@ -501,9 +501,11 @@ public:
break;
}
case GRP_WIDGET_CREATE_GROUP: // Create a new group
DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE));
case GRP_WIDGET_CREATE_GROUP: { // Create a new group
extern void CcCreateGroup(bool success, TileIndex tile, uint32 p1, uint32 p2);
DoCommandP(0, this->vehicle_type, 0, CMD_CREATE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_CREATE), CcCreateGroup);
break;
}
case GRP_WIDGET_DELETE_GROUP: { // Delete the selected group
GroupID group = this->group_sel;
@ -513,16 +515,9 @@ public:
break;
}
case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
assert(Group::IsValidID(this->group_sel));
const Group *g = Group::Get(this->group_sel);
this->group_rename = this->group_sel;
SetDParam(0, g->index);
ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
} break;
case GRP_WIDGET_RENAME_GROUP: // Rename the selected roup
this->ShowRenameGroupWindow(this->group_sel);
break;
case GRP_WIDGET_AVAILABLE_VEHICLES:
ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type);
@ -684,6 +679,14 @@ public:
this->InvalidateWidget(GRP_WIDGET_LIST_VEHICLE);
}
void ShowRenameGroupWindow(GroupID group)
{
assert(Group::IsValidID(group));
this->group_rename = group;
SetDParam(0, group);
ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
}
/**
* Tests whether a given vehicle is selected in the window, and unselects it if necessary.
* Called when the vehicle is deleted.
@ -712,21 +715,45 @@ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
AllocateWindowDescFront<VehicleGroupWindow>(&_group_desc, num);
}
/**
* Finds a group list window determined by vehicle type and owner
* @param vt vehicle type
* @param owner owner of groups
* @return pointer to VehicleGroupWindow, NULL if not found
*/
static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner)
{
return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | owner);
}
/**
* Opens a 'Rename group' window for newly created group
* @param success did command succeed?
* @param tile unused
* @param p1 vehicle type
* @param p2 unused
* @see CmdCreateGroup
*/
void CcCreateGroup(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
if (!success) return;
assert(p1 <= VEH_AIRCRAFT);
VehicleGroupWindow *w = FindVehicleGroupWindow((VehicleType)p1, _current_company);
if (w != NULL) w->ShowRenameGroupWindow(_new_group_id);
}
/**
* Removes the highlight of a vehicle in a group window
* @param *v Vehicle to remove all highlights from
*/
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
{
VehicleGroupWindow *w;
/* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any group windows either
* If that is the case, we can skip looping though the windows and save time
*/
if (_special_mouse_mode != WSM_DRAGDROP) return;
VehicleType vehicle_type = v->type;
w = dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vehicle_type), (vehicle_type << 11) | VLW_GROUP_LIST | v->owner));
VehicleGroupWindow *w = FindVehicleGroupWindow(v->type, v->owner);
if (w != NULL) w->UnselectVehicle(v->index);
}

Loading…
Cancel
Save