summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-01-16 18:25:23 +0000
committerpeter1138 <peter1138@openttd.org>2008-01-16 18:25:23 +0000
commit330ec8bdd660a2868e5c280f916efc519bc611af (patch)
tree6e6ea4e93ca1f83d42c4ea75113b7361e37a6937
parentabac83795dd451f8d14c7ee1738f91d4046dc59a (diff)
downloadopenttd-330ec8bdd660a2868e5c280f916efc519bc611af.tar.xz
(svn r11880) -Codechange: Generate vehicle group action dropdown dynamically, and assign an enum for the function return codes.
-rw-r--r--src/group_gui.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 21f3e2594..b66d0c138 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -23,6 +23,7 @@
#include "viewport_func.h"
#include "gfx_func.h"
#include "player_func.h"
+#include "widgets/dropdown_type.h"
#include "widgets/dropdown_func.h"
#include "table/strings.h"
@@ -258,6 +259,14 @@ static void CreateVehicleGroupWindow(Window *w)
}
}
+enum GroupActionListFunction {
+ GALF_REPLACE,
+ GALF_SERVICE,
+ GALF_DEPOT,
+ GALF_ADD_SHARED,
+ GALF_REMOVE_ALL,
+};
+
/**
* Update/redraw the group action dropdown
* @param w the window the dropdown belongs to
@@ -265,19 +274,18 @@ static void CreateVehicleGroupWindow(Window *w)
*/
static void ShowGroupActionDropdown(Window *w, GroupID gid)
{
- static StringID action_str[] = {
- STR_REPLACE_VEHICLES,
- STR_SEND_FOR_SERVICING,
- STR_SEND_TRAIN_TO_DEPOT,
- STR_NULL,
- STR_NULL,
- INVALID_STRING_ID
- };
-
- action_str[3] = IsValidGroupID(gid) ? STR_GROUP_ADD_SHARED_VEHICLE : INVALID_STRING_ID;
- action_str[4] = IsValidGroupID(gid) ? STR_GROUP_REMOVE_ALL_VEHICLES : INVALID_STRING_ID;
-
- ShowDropDownMenu(w, action_str, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, 0);
+ DropDownList *list = new DropDownList();
+
+ list->push_back(new DropDownListStringItem(STR_REPLACE_VEHICLES, GALF_REPLACE, false));
+ list->push_back(new DropDownListStringItem(STR_SEND_FOR_SERVICING, GALF_SERVICE, false));
+ list->push_back(new DropDownListStringItem(STR_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false));
+
+ if (IsValidGroupID(gid)) {
+ list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, GALF_ADD_SHARED, false));
+ list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false));
+ }
+
+ ShowDropDownList(w, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
}
/**
@@ -707,24 +715,24 @@ static void GroupWndProc(Window *w, WindowEvent *e)
assert(gv->l.list_length != 0);
switch (e->we.dropdown.index) {
- case 0: // Replace window
+ case GALF_REPLACE: // Replace window
ShowReplaceGroupVehicleWindow(gv->group_sel, gv->vehicle_type);
break;
- case 1: // Send for servicing
+ case GALF_SERVICE: // Send for servicing
DoCommandP(0, gv->group_sel, ((IsAllGroupID(gv->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
| DEPOT_MASS_SEND
| DEPOT_SERVICE, NULL, GetCmdSendToDepot(gv->vehicle_type));
break;
- case 2: // Send to Depots
+ case GALF_DEPOT: // Send to Depots
DoCommandP(0, gv->group_sel, ((IsAllGroupID(gv->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK)
| DEPOT_MASS_SEND, NULL, GetCmdSendToDepot(gv->vehicle_type));
break;
- case 3: // Add shared Vehicles
+ case GALF_ADD_SHARED: // Add shared Vehicles
assert(IsValidGroupID(gv->group_sel));
DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
break;
- case 4: // Remove all Vehicles from the selected group
+ case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
assert(IsValidGroupID(gv->group_sel));
DoCommandP(0, gv->group_sel, gv->vehicle_type, NULL, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));