diff --git a/cm_changelog.txt b/cm_changelog.txt index 5f041d8def..8bd8f11ad8 100644 --- a/cm_changelog.txt +++ b/cm_changelog.txt @@ -76,6 +76,7 @@ This is usable for any OpenTTD servers *** 14.0 *** - Fixed graphs with cargo selection. - Fixed measurement tooltips. +- Show the number of hidden vehicles in buy and autoreplace windows. - Added a setting to disable activate-on-release behaviour of toolbar dropdown buttons. - Added Russian translation. diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index fa19ba4541..55e2dc2413 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -94,6 +94,8 @@ class ReplaceVehicleWindow : public Window { RoadType sel_roadtype; ///< Type of road selected. #INVALID_ROADTYPE to show all. Scrollbar *vscroll[2]; + uint cm_num_hidden_engines; + /** * Figure out if an engine should be added to a list. * @param e The EngineID. @@ -148,9 +150,10 @@ class ReplaceVehicleWindow : public Window { byte side = draw_left ? 0 : 1; GUIEngineList list; + this->cm_num_hidden_engines = 0; for (const Engine *e : Engine::IterateType(type)) { - if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; + // CM num_hidden if (!draw_left && !this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; EngineID eid = e->index; switch (type) { case VEH_TRAIN: @@ -175,6 +178,10 @@ class ReplaceVehicleWindow : public Window { if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue; } else { if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue; + if (e->IsVariantHidden(_local_company)) { + this->cm_num_hidden_engines++; + if (!this->show_hidden_engines) continue; + } } list.emplace_back(eid, e->info.variant_id, (side == 0) ? EngineDisplayFlags::None : e->display_flags, 0); @@ -306,7 +313,7 @@ public: this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR); NWidgetCore *widget = this->GetWidget(WID_RV_SHOW_HIDDEN_ENGINES); - widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype; + widget->widget_data = CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype; widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype; widget->SetLowered(this->show_hidden_engines); this->FinishInitNested(vehicletype); @@ -456,6 +463,10 @@ public: case WID_RV_ROAD_TYPE_DROPDOWN: SetDParam(0, this->sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(this->sel_roadtype)->strings.replace_text); break; + + case WID_RV_SHOW_HIDDEN_ENGINES: + SetDParam(0, this->cm_num_hidden_engines); + break; } } @@ -501,7 +512,17 @@ public: void OnPaint() override { - if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists(); + /* CityMania code start */ + //if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists(); + if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) { + auto old_num_hidden_engines = this->cm_num_hidden_engines; + this->GenerateLists(); + if (old_num_hidden_engines != this->cm_num_hidden_engines) { + this->ReInit(); + return; + } + } + /* CityMania code end */ Company *c = Company::Get(_local_company); @@ -764,7 +785,7 @@ static constexpr NWidgetPart _nested_replace_rail_vehicle_widgets[] = { NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(), EndContainer(), EndContainer(), @@ -825,7 +846,7 @@ static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = { NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(), EndContainer(), EndContainer(), @@ -880,7 +901,7 @@ static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = { NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP), NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(), EndContainer(), EndContainer(), diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index eb9d6a1f7b..bf59bf9931 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -7,6 +7,7 @@ /** @file build_vehicle_gui.cpp GUI for building vehicles. */ +#include "engine_type.h" #include "stdafx.h" #include "engine_base.h" #include "engine_func.h" @@ -1150,6 +1151,7 @@ struct BuildVehicleWindow : Window { StringFilter string_filter; ///< Filter for vehicle name QueryString vehicle_editbox; ///< Filter editbox + uint cm_num_hidden_engines; void SetBuyVehicleText() { @@ -1200,7 +1202,10 @@ struct BuildVehicleWindow : Window { this->descending_sort_order = _engine_sort_last_order[type]; this->show_hidden_engines = _engine_sort_show_hidden_engines[type]; + this->SetCargoFilterArray(); // CM this->UpdateFilterByTile(); + this->eng_list.ForceRebuild(); // CM + this->GenerateBuildList(); // CM Needs to be before FinishInitNested to calculate num_hidden_engines for SetStringParameters this->CreateNestedTree(); @@ -1221,7 +1226,7 @@ struct BuildVehicleWindow : Window { widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type; widget = this->GetWidget(WID_BV_SHOW_HIDDEN_ENGINES); - widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type; + widget->widget_data = CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type; widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type; widget->SetLowered(this->show_hidden_engines); @@ -1238,8 +1243,8 @@ struct BuildVehicleWindow : Window { this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company; - this->eng_list.ForceRebuild(); - this->GenerateBuildList(); // generate the list, since we need it in the next line + // CM moved up this->eng_list.ForceRebuild(); + // CM moved up this->GenerateBuildList(); // generate the list, since we need it in the next line /* Select the first unshaded engine in the list as default when opening the window */ EngineID engine = INVALID_ENGINE; @@ -1329,19 +1334,22 @@ struct BuildVehicleWindow : Window { this->te.FillDefaultCapacities(e); } - void OnInit() override - { - this->SetCargoFilterArray(); - } + // CM calls this in constructor + // void OnInit() override + // { + // this->SetCargoFilterArray(); + // } /** Filter the engine list against the currently selected cargo filter */ - void FilterEngineList() + EngineID FilterEngineList() { this->eng_list.Filter(this->cargo_filter_criteria); if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine - this->SelectEngine(INVALID_ENGINE); + // CM this->SelectEngine(INVALID_ENGINE); + return INVALID_ENGINE; } else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list - this->SelectEngine(this->eng_list[0].engine_id); + // CM this->SelectEngine(this->eng_list[0].engine_id); + return this->eng_list[0].engine_id; } } @@ -1371,11 +1379,12 @@ struct BuildVehicleWindow : Window { } /* Figure out what train EngineIDs to put in the list */ - void GenerateBuildTrainList(GUIEngineList &list) + EngineID GenerateBuildTrainList(GUIEngineList &list) { std::vector variants; EngineID sel_id = INVALID_ENGINE; size_t num_engines = 0; + this->cm_num_hidden_engines = 0; list.clear(); @@ -1384,7 +1393,7 @@ struct BuildVehicleWindow : Window { * and if not, reset selection to INVALID_ENGINE. This could be the case * when engines become obsolete and are removed */ for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { - if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; + // CM for num_hidden / if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; EngineID eid = e->index; const RailVehicleInfo *rvi = &e->u.rail; @@ -1397,6 +1406,14 @@ struct BuildVehicleWindow : Window { /* Filter by name or NewGRF extra text */ if (!FilterByText(e)) continue; + /* CityMania code start */ + /* Note: needs to be the last check to calculate the number correctly */ + if (e->IsVariantHidden(_local_company)) { + this->cm_num_hidden_engines++; + if (!this->show_hidden_engines) continue; + } + /* CityMania code end */ + list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); if (rvi->railveh_type != RAILVEH_WAGON) num_engines++; @@ -1420,7 +1437,7 @@ struct BuildVehicleWindow : Window { } } - this->SelectEngine(sel_id); + // CM for num_hidden / this->SelectEngine(sel_id); /* invalidate cached values for name sorter - engine names could change */ _last_engine[0] = _last_engine[1] = INVALID_ENGINE; @@ -1435,17 +1452,20 @@ struct BuildVehicleWindow : Window { /* and finally sort wagons */ EngList_SortPartial(list, _engine_sort_functions[0][this->sort_criteria], num_engines, list.size() - num_engines); + + return sel_id; // CM } /* Figure out what road vehicle EngineIDs to put in the list */ void GenerateBuildRoadVehList() { - EngineID sel_id = INVALID_ENGINE; + // CM num_hidden / EngineID sel_id = INVALID_ENGINE; + this->cm_num_hidden_engines = 0; this->eng_list.clear(); for (const Engine *e : Engine::IterateType(VEH_ROAD)) { - if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; + // CM num_hidden / if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; EngineID eid = e->index; if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue; if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->u.road.roadtype, this->filter.roadtype)) continue; @@ -1453,17 +1473,25 @@ struct BuildVehicleWindow : Window { /* Filter by name or NewGRF extra text */ if (!FilterByText(e)) continue; - this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + /* CityMania code start */ + // this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + // if (eid == this->sel_engine) sel_id = eid; + /* Note: needs to be the last check to calculate the number correctly */ + if (e->IsVariantHidden(_local_company)) { + this->cm_num_hidden_engines++; + if (!this->show_hidden_engines) continue; + } - if (eid == this->sel_engine) sel_id = eid; + this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + /* CityMania code end */ } - this->SelectEngine(sel_id); } /* Figure out what ship EngineIDs to put in the list */ void GenerateBuildShipList() { - EngineID sel_id = INVALID_ENGINE; + // CM EngineID sel_id = INVALID_ENGINE; + this->cm_num_hidden_engines = 0; this->eng_list.clear(); for (const Engine *e : Engine::IterateType(VEH_SHIP)) { @@ -1474,17 +1502,25 @@ struct BuildVehicleWindow : Window { /* Filter by name or NewGRF extra text */ if (!FilterByText(e)) continue; - this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + /* CityMania code start */ + // this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + // if (eid == this->sel_engine) sel_id = eid; + /* Note: needs to be the last check to calculate the number correctly */ + if (e->IsVariantHidden(_local_company)) { + this->cm_num_hidden_engines++; + if (!this->show_hidden_engines) continue; + } - if (eid == this->sel_engine) sel_id = eid; + this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + /* CityMania code end */ } - this->SelectEngine(sel_id); } /* Figure out what aircraft EngineIDs to put in the list */ void GenerateBuildAircraftList() { - EngineID sel_id = INVALID_ENGINE; + // CM num_hidden / EngineID sel_id = INVALID_ENGINE; + this->cm_num_hidden_engines = 0; this->eng_list.clear(); @@ -1504,18 +1540,23 @@ struct BuildVehicleWindow : Window { /* Filter by name or NewGRF extra text */ if (!FilterByText(e)) continue; + /* CityMania code start */ + // this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); + // if (eid == this->sel_engine) sel_id = eid; + /* Note: needs to be the last check to calculate the number correctly */ + if (e->IsVariantHidden(_local_company)) { + this->cm_num_hidden_engines++; + if (!this->show_hidden_engines) continue; + } + this->eng_list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); - - if (eid == this->sel_engine) sel_id = eid; - } - - this->SelectEngine(sel_id); + /* CityMania code end */ } } /* Generate the list of vehicles */ - void GenerateBuildList() + EngineID GenerateBuildList() { - if (!this->eng_list.NeedRebuild()) return; + if (!this->eng_list.NeedRebuild()) return this->sel_engine; // CM return /* Update filter type in case the road/railtype of the depot got converted */ this->UpdateFilterByTile(); @@ -1523,15 +1564,16 @@ struct BuildVehicleWindow : Window { this->eng_list.clear(); GUIEngineList list; + EngineID sel_id = INVALID_ENGINE; // CM switch (this->vehicle_type) { default: NOT_REACHED(); case VEH_TRAIN: - this->GenerateBuildTrainList(list); + sel_id = this->GenerateBuildTrainList(list); // CM AddChildren(list, INVALID_ENGINE, 0); this->eng_list.shrink_to_fit(); this->eng_list.RebuildDone(); - return; + return sel_id; // CM case VEH_ROAD: this->GenerateBuildRoadVehList(); break; @@ -1543,7 +1585,7 @@ struct BuildVehicleWindow : Window { break; } - this->FilterEngineList(); + sel_id = this->FilterEngineList(); // CM change /* ensure primary engine of variant group is in list after filtering */ std::vector variants; @@ -1569,6 +1611,8 @@ struct BuildVehicleWindow : Window { AddChildren(list, INVALID_ENGINE, 0); this->eng_list.shrink_to_fit(); this->eng_list.RebuildDone(); + + return sel_id; // CM } DropDownList BuildCargoDropDownList() const @@ -1748,6 +1792,10 @@ struct BuildVehicleWindow : Window { } break; } + + case WID_BV_SHOW_HIDDEN_ENGINES: + SetDParam(0, this->cm_num_hidden_engines); + break; } } @@ -1816,8 +1864,20 @@ struct BuildVehicleWindow : Window { void OnPaint() override { - this->GenerateBuildList(); - this->vscroll->SetCount(this->eng_list.size()); + /* CityMania code start */ + // this->GenerateBuildList(); + // this->vscroll->SetCount(this->eng_list.size()); + uint old_num_hidden_engines = this->cm_num_hidden_engines; + EngineID sel_id = this->GenerateBuildList(); + if (sel_id != this->sel_engine) this->SelectEngine(sel_id); + if (old_num_hidden_engines != this->cm_num_hidden_engines) { + this->ReInit(); + return; + } + + this->vscroll->SetCount( + this->eng_list.size()); + /* CityMania code end */ this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD); diff --git a/src/lang/english.txt b/src/lang/english.txt index 110990cd09..4f9266a9e8 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -6302,3 +6302,9 @@ CM_STR_VEHICLE_INFO_BUILT_VALUE_WITH_ID :{LTBLUE}{ENGINE CM_STR_CONFIG_SETTING_TOOLBAR_DROPDOWN_CLOSE :Toolbar dropdowns activate on release: {STRING2} CM_STR_CONFIG_SETTING_TOOLBAR_DROPDOWN_CLOSE_HELPTEXT :Control whether the main toolbar dropdowns activate their default function when the mouse button is released. If not enabled then the dropdown menu will stay open so a selection can be made. + +###length VEHICLE_TYPES +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN :{BLACK}Show hidden ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_ROAD_VEHICLE :{BLACK}Show hidden ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_SHIP :{BLACK}Show hidden ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT :{BLACK}Show hidden ({NUM}) diff --git a/src/lang/russian.txt b/src/lang/russian.txt index 3e5993b216..5ac548826a 100644 --- a/src/lang/russian.txt +++ b/src/lang/russian.txt @@ -6523,5 +6523,11 @@ CM_STR_BUILD_INFO_OVERLAY_ERROR_UNKNOWN :{RED}Неизв CM_STR_VEHICLE_INFO_BUILT_VALUE_WITH_ID :{LTBLUE}{ENGINE} {BLACK}Построен в {LTBLUE}{NUM} г.{BLACK} Стоимость: {LTBLUE}{CURRENCY_LONG}{BLACK} ID: {LTBLUE}{NUM} -CM_STR_CONFIG_SETTING_TOOLBAR_DROPDOWN_CLOSE :Активировать выпадающие меню при отпускании клавиши: {STRING2} +CM_STR_CONFIG_SETTING_TOOLBAR_DROPDOWN_CLOSE :Активировать выпадающие меню при отпускании клавиши: {STRING} CM_STR_CONFIG_SETTING_TOOLBAR_DROPDOWN_CLOSE_HELPTEXT :Контролирует, активируют ли выпадающие меню основной панели инструментов свою стандартную функцию при отпускании кнопки мыши. Если выключено, то выпадающее меню останется открытым, чтобы можно было сделать выбор. + +###length VEHICLE_TYPES +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN :{BLACK}Показать скрытые ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_ROAD_VEHICLE :{BLACK}Показать скрытые ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_SHIP :{BLACK}Показать скрытые ({NUM}) +CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT :{BLACK}Показать скрытые ({NUM})