diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index bd4bf3b59b..ab988847da 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -81,6 +81,9 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = { NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0), EndContainer(), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_REFIT_SEL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_BUILD_REFIT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_BUTTON, STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_TOOLTIP), + EndContainer(), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0), NWidget(WWT_RESIZEBOX, COLOUR_GREY), @@ -96,6 +99,7 @@ byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Las bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type. bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type. static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}; ///< Last set filter criteria, for each vehicle type. +static bool _refit_on_buy = false; ///< to save user's choice for at least this game session /** * Determines order of engines by engineID @@ -974,6 +978,7 @@ struct BuildVehicleWindow : Window { byte cargo_filter_criteria; ///< Selected cargo filter int details_height; ///< Minimal needed height of the details panels (found so far). Scrollbar *vscroll; + bool build_and_refit; ///< Build and refit. This is beauty, but we need some persistence to save user choice for this game session at least BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc) { @@ -1006,7 +1011,10 @@ struct BuildVehicleWindow : Window { /* If we are just viewing the list of vehicles, we do not need the Build button. * So we just hide it, and enlarge the Rename button by the now vacant place. */ - if (this->listview_mode) this->GetWidget(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE); + if (this->listview_mode) { + this->GetWidget(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE); + this->GetWidget(WID_BV_BUILD_REFIT_SEL)->SetDisplayedPlane(SZSP_NONE); + } /* disable renaming engines in network games if you are not the server */ this->SetWidgetDisabledState(WID_BV_RENAME, _networking && !_network_server); @@ -1017,6 +1025,9 @@ struct BuildVehicleWindow : Window { widget = this->GetWidget(WID_BV_SHOW_HIDE); widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type; + this->build_and_refit = _refit_on_buy; + this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit); + widget = this->GetWidget(WID_BV_BUILD); widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + type; widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + type; @@ -1305,11 +1316,22 @@ struct BuildVehicleWindow : Window { break; } + case WID_BV_BUILD_REFIT: { + _refit_on_buy = this->build_and_refit = !this->build_and_refit; + this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit); + this->SetDirty(); + break; + } + case WID_BV_BUILD: { EngineID sel_eng = this->sel_engine; if (sel_eng != INVALID_ENGINE) { CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle; - DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback); + if (DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback) && + !this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) { + // refit to selected cargo filter + DoCommandP(this->window_number, _new_vehicle_id, this->cargo_filter[this->cargo_filter_criteria], GetCmdRefitVeh(this->vehicle_type)); + } } break; } @@ -1426,6 +1448,13 @@ struct BuildVehicleWindow : Window { this->SetWidgetDisabledState(WID_BV_SHOW_HIDE, this->sel_engine == INVALID_ENGINE); + // disable build and refit if all or none cargo type selected + if (this->cargo_filter[this->cargo_filter_criteria] == CF_ANY || this->cargo_filter[this->cargo_filter_criteria] == CF_NONE) { + this->DisableWidget(WID_BV_BUILD_REFIT); + } else { + this->EnableWidget(WID_BV_BUILD_REFIT); + } + this->DrawWidgets(); if (!this->IsShaded()) { diff --git a/src/lang/english.txt b/src/lang/english.txt index 545628aca3..07d493900c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3828,6 +3828,9 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_LIST_TOOLTIP :{BLACK}Road veh STR_BUY_VEHICLE_SHIP_LIST_TOOLTIP :{BLACK}Ship selection list. Click on ship for information. Ctrl+Click for toggling hiding of the ship type STR_BUY_VEHICLE_AIRCRAFT_LIST_TOOLTIP :{BLACK}Aircraft selection list. Click on aircraft for information. Ctrl+Click for toggling hiding of the aircraft type +STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Refit after buy +STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Automatically refit the highlighted vehicle after buying to selected cargo type + STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON :{BLACK}Buy Vehicle STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Buy Vehicle STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Buy Ship diff --git a/src/lang/russian.txt b/src/lang/russian.txt index e35a8e6307..36fd3f02ab 100644 --- a/src/lang/russian.txt +++ b/src/lang/russian.txt @@ -3586,6 +3586,9 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_LIST_TOOLTIP :{BLACK}Спис STR_BUY_VEHICLE_SHIP_LIST_TOOLTIP :{BLACK}Список кораблей - щёлкните для получения информации. Ctrl+щелчок скроет/покажет выбранный корабль. STR_BUY_VEHICLE_AIRCRAFT_LIST_TOOLTIP :{BLACK}Список воздушных судов - щёлкните для получения информации. Ctrl+щелчок скроет/покажет ТС. +STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Переоборудовать +STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Переоборудовать купленное транспортное средство сразу после покупки для выделенного вида груза + STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON :{BLACK}Купить STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Купить STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Купить diff --git a/src/widgets/build_vehicle_widget.h b/src/widgets/build_vehicle_widget.h index ae548587e2..7d1cd1cb19 100644 --- a/src/widgets/build_vehicle_widget.h +++ b/src/widgets/build_vehicle_widget.h @@ -26,6 +26,8 @@ enum BuildVehicleWidgets { WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine. WID_BV_BUILD_SEL, ///< Build button. WID_BV_RENAME, ///< Rename button. + WID_BV_BUILD_REFIT, + WID_BV_BUILD_REFIT_SEL, }; #endif /* WIDGETS_BUILD_VEHICLE_WIDGET_H */