From 4dfd6a096f82b6a80629f373b2e2a1f11246891f Mon Sep 17 00:00:00 2001 From: PeterN Date: Tue, 24 Jan 2023 00:05:42 +0000 Subject: [PATCH] Fix #10220: Don't select unselectable engine as default. (#10404) --- src/build_vehicle_gui.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 6b5746ae4e..a4d425783b 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1188,12 +1188,12 @@ struct BuildVehicleWindow : Window { this->eng_list.ForceRebuild(); this->GenerateBuildList(); // generate the list, since we need it in the next line - /* Select the first engine in the list as default when opening the window */ - if (this->eng_list.size() > 0) { - this->SelectEngine(this->eng_list[0].engine_id); - } else { - this->SelectEngine(INVALID_ENGINE); - } + + /* Select the first unshaded engine in the list as default when opening the window */ + EngineID engine = INVALID_ENGINE; + auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; }); + if (it != this->eng_list.end()) engine = it->engine_id; + this->SelectEngine(engine); } /** Set the filter type according to the depot type */