MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildVehicleWindow

Method BuildVehicleWindow

src/build_vehicle_gui.cpp:1195–1249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1193 }
1194
1195 BuildVehicleWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
1196 {
1197 this->vehicle_type = type;
1198 this->listview_mode = tile == INVALID_TILE;
1199 this->window_number = this->listview_mode ? (int)type : tile.base();
1200
1201 this->sort_criteria = _engine_sort_last_criteria[type];
1202 this->descending_sort_order = _engine_sort_last_order[type];
1203 this->show_hidden_engines = _engine_sort_show_hidden_engines[type];
1204
1205 this->UpdateFilterByTile();
1206
1207 this->CreateNestedTree();
1208
1209 this->vscroll = this->GetScrollbar(WID_BV_SCROLLBAR);
1210
1211 /* If we are just viewing the list of vehicles, we do not need the Build button.
1212 * So we just hide it, and enlarge the Rename button by the now vacant place. */
1213 if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
1214
1215 NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
1216 widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type);
1217
1218 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
1219 widget->SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type);
1220
1221 widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
1222 widget->SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type, STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type);
1223
1224 widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
1225 widget->SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type);
1226 widget->SetLowered(this->show_hidden_engines);
1227
1228 this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
1229
1230 if (tile == INVALID_TILE) {
1231 this->FinishInitNested(type);
1232 } else {
1233 this->FinishInitNested(tile);
1234 }
1235
1236 this->querystrings[WID_BV_FILTER] = &this->vehicle_editbox;
1237 this->vehicle_editbox.cancel_button = QueryString::ACTION_CLEAR;
1238
1239 this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
1240
1241 this->eng_list.ForceRebuild();
1242 this->GenerateBuildList(); // generate the list, since we need it in the next line
1243
1244 /* Select the first unshaded engine in the list as default when opening the window */
1245 EngineID engine = EngineID::Invalid();
1246 auto it = std::ranges::find_if(this->eng_list, [](const GUIEngineListItem &item) { return !item.flags.Test(EngineDisplayFlag::Shaded); });
1247 if (it != this->eng_list.end()) engine = it->engine_id;
1248 this->SelectEngine(engine);
1249 }
1250
1251 /** Set the filter type according to the depot type */
1252 void UpdateFilterByTile()

Callers

nothing calls this directly

Calls 15

UpdateFilterByTileMethod · 0.95
GenerateBuildListMethod · 0.95
SelectEngineMethod · 0.95
GetTileOwnerFunction · 0.85
InvalidFunction · 0.85
CreateNestedTreeMethod · 0.80
GetScrollbarMethod · 0.80
SetDisplayedPlaneMethod · 0.80
SetToolTipMethod · 0.80
SetStringTipMethod · 0.80
SetLoweredMethod · 0.80
FinishInitNestedMethod · 0.80

Tested by

no test coverage detected