Skip to content

Commit

Permalink
Show the number of hidden vehicles in buy and autoreplace windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Apr 19, 2024
1 parent 007f2a8 commit 35cbdf8
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 42 deletions.
1 change: 1 addition & 0 deletions cm_changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
33 changes: 27 additions & 6 deletions src/autoreplace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down Expand Up @@ -306,7 +313,7 @@ class ReplaceVehicleWindow : public Window {
this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);

NWidgetCore *widget = this->GetWidget<NWidgetCore>(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);
Expand Down Expand Up @@ -456,6 +463,10 @@ class ReplaceVehicleWindow : public Window {
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;
}
}

Expand Down Expand Up @@ -501,7 +512,17 @@ class ReplaceVehicleWindow : public Window {

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);

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 35cbdf8

Please sign in to comment.