From cc1d72c3a370f3c9a13e8722f8d69f5735b95285 Mon Sep 17 00:00:00 2001 From: stormcone <48624099+stormcone@users.noreply.github.com> Date: Fri, 10 May 2019 19:49:50 +0200 Subject: [PATCH] Feature: Control + click on the vehicle details button in the vehicle view window opens the vehicle group window, then selects and scrolls to the vehicle's group. --- src/group_gui.cpp | 21 +++++++++++++++++---- src/group_gui.h | 3 ++- src/vehicle_gui.cpp | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 8d7c042d2e..842e3fbb0e 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -1046,18 +1046,31 @@ static WindowDesc _train_group_desc( * Show the group window for the given company and vehicle type. * @param company The company to show the window for. * @param vehicle_type The type of vehicle to show it for. + * @param group The group to be selected. Defaults to INVALID_GROUP. + * @param need_existing_window Whether the existing window is needed. Defaults to false. */ -void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type) +void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group = INVALID_GROUP, bool need_existing_window = false) { if (!Company::IsValidID(company)) return; - WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack(); + const WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack(); + VehicleGroupWindow *w; if (vehicle_type == VEH_TRAIN) { - AllocateWindowDescFront(&_train_group_desc, num); + w = AllocateWindowDescFront(&_train_group_desc, num, need_existing_window); } else { _other_group_desc.cls = GetWindowClassForVehicleType(vehicle_type); - AllocateWindowDescFront(&_other_group_desc, num); + w = AllocateWindowDescFront(&_other_group_desc, num, need_existing_window); } + if (w != nullptr) w->SelectGroup(group); +} + +/** + * Show the group window for the given vehicle. + * @param v The vehicle to show the window for. + */ +void ShowCompanyGroupForVehicle(const Vehicle *v) +{ + ShowCompanyGroup(v->owner, v->type, v->group_id, true); } /** diff --git a/src/group_gui.h b/src/group_gui.h index 6a0ddfb7a7..d42704663e 100644 --- a/src/group_gui.h +++ b/src/group_gui.h @@ -13,7 +13,8 @@ #include "company_type.h" #include "vehicle_type.h" -void ShowCompanyGroup(CompanyID company, VehicleType veh); +void ShowCompanyGroup(CompanyID company, VehicleType veh, GroupID group = INVALID_GROUP, bool need_existing_window = false); +void ShowCompanyGroupForVehicle(const Vehicle *v); void DeleteGroupHighlightOfVehicle(const Vehicle *v); #endif /* GROUP_GUI_H */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 04d240b04a..6272459bc2 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2698,7 +2698,11 @@ public: } break; case WID_VV_SHOW_DETAILS: // show details - ShowVehicleDetailsWindow(v); + if (_ctrl_pressed) { + ShowCompanyGroupForVehicle(v); + } else { + ShowVehicleDetailsWindow(v); + } break; case WID_VV_CLONE: // clone vehicle /* Suppress the vehicle GUI when share-cloning.