Add: Adding and removing whole classes to collections (#15808)

This commit is contained in:
mmtunligit
2026-07-10 06:54:50 -04:00
committed by GitHub
parent 9f8ac2aaa1
commit a961e64928
2 changed files with 33 additions and 6 deletions
+6 -6
View File
@@ -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
+27
View File
@@ -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);