summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/callback_table.cpp4
-rw-r--r--src/group_gui.cpp61
2 files changed, 48 insertions, 17 deletions
diff --git a/src/callback_table.cpp b/src/callback_table.cpp
index 8bf13f5f2..d0caf7b88 100644
--- a/src/callback_table.cpp
+++ b/src/callback_table.cpp
@@ -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);
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 5a24b4ef1..1c220a083 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -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.
@@ -713,20 +716,44 @@ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
}
/**
+ * 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);
}
-