From 78243fbd3ddb45a1f0eddaaed534c45ab5518bf2 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 20 May 2007 18:34:47 +0000 Subject: (svn r9891) -Fix [FS#787]: the manage list menu wasn't removed/updated when changing to another group making it able to perform "group" actions for "all vehicles", which would cause a crash. --- src/group_gui.cpp | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 8a486d644..4d5ab44eb 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -257,6 +257,30 @@ static void CreateVehicleGroupWindow(Window *w) } } +/** + * Update/redraw the group action dropdown + * @param w the window the dropdown belongs to + * @param gid the currently selected group in the window + */ +static void UpdateGroupActionDropdown(Window *w, GroupID gid, bool refresh = true) +{ + if (refresh && !IsWindowWidgetLowered(w, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) return; + + 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] = IsDefaultGroupID(gid) ? INVALID_STRING_ID : STR_GROUP_ADD_SHARED_VEHICLE; + action_str[4] = IsDefaultGroupID(gid) ? INVALID_STRING_ID : STR_GROUP_REMOVE_ALL_VEHICLES; + + ShowDropDownMenu(w, action_str, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, 0); +} + /** * bitmask for w->window_number * 0-7 PlayerID (owner) @@ -464,6 +488,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) if (!IsDefaultGroupID(gv->group_sel)) { gv->group_sel = DEFAULT_GROUP; gv->l.flags |= VL_REBUILD; + UpdateGroupActionDropdown(w, gv->group_sel); SetWindowDirty(w); } break; @@ -480,6 +505,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) gv->group_sel = gl->sort_list[id_g]->index;; gv->l.flags |= VL_REBUILD; + UpdateGroupActionDropdown(w, gv->group_sel); SetWindowDirty(w); break; } @@ -518,8 +544,9 @@ static void GroupWndProc(Window *w, WindowEvent *e) case GRP_WIDGET_CREATE_GROUP: // Create a new group if (!CmdFailed(DoCommandP(0, gv->vehicle_type, 0, NULL, CMD_CREATE_GROUP | CMD_MSG(STR_GROUP_CAN_T_CREATE)))) { - SetWindowDirty(w); gl->l.flags |= VL_REBUILD; + UpdateGroupActionDropdown(w, gv->group_sel); + SetWindowDirty(w); } break; @@ -528,6 +555,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) gv->group_sel = DEFAULT_GROUP; gv->l.flags |= VL_REBUILD; gl->l.flags |= VL_REBUILD; + UpdateGroupActionDropdown(w, gv->group_sel); SetWindowDirty(w); } break; @@ -548,19 +576,7 @@ static void GroupWndProc(Window *w, WindowEvent *e) case GRP_WIDGET_MANAGE_VEHICLES: case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: { - 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] = IsDefaultGroupID(gv->group_sel) ? INVALID_STRING_ID : STR_GROUP_ADD_SHARED_VEHICLE; - action_str[4] = IsDefaultGroupID(gv->group_sel) ? INVALID_STRING_ID : STR_GROUP_REMOVE_ALL_VEHICLES; - - ShowDropDownMenu(w, action_str, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN, 0, 0); + UpdateGroupActionDropdown(w, gv->group_sel, false); break; } -- cgit v1.2.3-70-g09d2