Fix #10220: Don't select unselectable engine as default. (#10404)

This commit is contained in:
PeterN
2023-01-24 00:05:42 +00:00
committed by GitHub
parent 97844df123
commit 4dfd6a096f

View File

@@ -1188,12 +1188,12 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild(); this->eng_list.ForceRebuild();
this->GenerateBuildList(); // generate the list, since we need it in the next line 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) { /* Select the first unshaded engine in the list as default when opening the window */
this->SelectEngine(this->eng_list[0].engine_id); EngineID engine = INVALID_ENGINE;
} else { auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
this->SelectEngine(INVALID_ENGINE); if (it != this->eng_list.end()) engine = it->engine_id;
} this->SelectEngine(engine);
} }
/** Set the filter type according to the depot type */ /** Set the filter type according to the depot type */