From a961e649280448fc3d65f70d2a674cc7af235897 Mon Sep 17 00:00:00 2001 From: mmtunligit <156685720+mmtunligit@users.noreply.github.com> Date: Fri, 10 Jul 2026 06:54:50 -0400 Subject: [PATCH] Add: Adding and removing whole classes to collections (#15808) --- src/lang/english.txt | 12 ++++++------ src/picker_gui.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index b7736a13f0..1ef056c01c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2888,22 +2888,22 @@ STR_PICKER_COLLECTION_DELETE_QUERY :Delete collecti STR_PICKER_COLLECTION_DELETE_QUERY_TEXT :{YELLOW}Are you sure you want to delete this collection? STR_PICKER_COLLECTION_DELETE_QUERY_DISABLED_TEXT :{YELLOW}Are you sure you want to delete this collection? There are items from disabled NewGRFs in it! -STR_PICKER_STATION_CLASS_TOOLTIP :Select a station class to display +STR_PICKER_STATION_CLASS_TOOLTIP :Select a station class to display. Ctrl+Click to add or remove in saved items STR_PICKER_STATION_TYPE_TOOLTIP :Select a station type to build. Ctrl+Click to add or remove in saved items STR_PICKER_STATION_COLLECTION_TOOLTIP :Select a collection of stations to display -STR_PICKER_WAYPOINT_CLASS_TOOLTIP :Select a waypoint class to display +STR_PICKER_WAYPOINT_CLASS_TOOLTIP :Select a waypoint class to display. Ctrl+Click to add or remove in saved items STR_PICKER_WAYPOINT_TYPE_TOOLTIP :Select a waypoint to build. Ctrl+Click to add or remove in saved items STR_PICKER_WAYPOINT_COLLECTION_TOOLTIP :Select a collection of waypoints to display -STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP :Select a bus station class to display +STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP :Select a bus station class to display. Ctrl+Click to add or remove in saved items STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP :Select a bus station type to build. Ctrl+Click to add or remove in saved items STR_PICKER_ROADSTOP_BUS_COLLECTION_TOOLTIP :Select a collection of bus stations to display -STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP :Select a lorry station class to display +STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP :Select a lorry station class to display. Ctrl+Click to add or remove in saved items STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP :Select a lorry station type to build. Ctrl+Click to add or remove in saved items STR_PICKER_ROADSTOP_TRUCK_COLLECTION_TOOLTIP :Select a collection of lorry stations to display -STR_PICKER_OBJECT_CLASS_TOOLTIP :Select an object class to display +STR_PICKER_OBJECT_CLASS_TOOLTIP :Select an object class to display. Ctrl+Click to add or remove in saved items STR_PICKER_OBJECT_TYPE_TOOLTIP :Select an object type to build. Ctrl+Click to add or remove in saved items. Ctrl+Click+Drag to select the area diagonally. Also press Shift to show cost estimate only STR_PICKER_OBJECT_COLLECTION_TOOLTIP :Select a collection of objects to display -STR_PICKER_HOUSE_CLASS_TOOLTIP :Select a town zone to display +STR_PICKER_HOUSE_CLASS_TOOLTIP :Select a town zone to display. Ctrl+Click to add or remove in saved items STR_PICKER_HOUSE_TYPE_TOOLTIP :Select a house type to build. Ctrl+Click to add or remove in saved items STR_PICKER_HOUSE_COLLECTION_TOOLTIP :Select a collection of houses to display diff --git a/src/picker_gui.cpp b/src/picker_gui.cpp index b0ee1bc761..5d49e745cf 100644 --- a/src/picker_gui.cpp +++ b/src/picker_gui.cpp @@ -458,6 +458,33 @@ void PickerWindow::OnClick(Point pt, WidgetID widget, int) auto it = vscroll->GetScrolledItemFromWidget(this->classes, pt.y, this, WID_PW_CLASS_LIST); if (it == this->classes.end()) return; + if (_ctrl_pressed) { + /* If no collections yet exist, create the default collection. */ + if (this->callbacks.saved.find(this->callbacks.sel_collection) == this->callbacks.saved.end()) { + for (int i = 0; i < this->callbacks.GetTypeCount(*it); i++) { + this->callbacks.saved[""].emplace(this->callbacks.GetPickerItem(*it, i)); + } + this->InvalidateData({PickerInvalidation::Collection, PickerInvalidation::Class}); + this->SetDirty(); + break; + } + + /* If the first item is not already saved to the selected collection, add the whole class to the collection. Otherwise remove the class. */ + auto &collection = this->callbacks.saved.at(this->callbacks.sel_collection); + auto first = collection.find(this->callbacks.GetPickerItem(*it, 0)); + if (first == std::end(collection)) { + for (int i = 0; i < this->callbacks.GetTypeCount(*it); i++) { + collection.emplace(this->callbacks.GetPickerItem(*it, i)); + } + } else { + for (int i = 0; i < this->callbacks.GetTypeCount(*it); i++) { + collection.erase(this->callbacks.GetPickerItem(*it, i)); + } + } + this->InvalidateData({PickerInvalidation::Type, PickerInvalidation::Class}); + break; + } + if (this->callbacks.GetSelectedClass() != *it || this->callbacks.mode.Test(PickerFilterMode::All)) { this->callbacks.mode.Reset(PickerFilterMode::All); // Disable showing all. this->callbacks.SetSelectedClass(*it);