1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Codechange: Use SetDisplayedPlane instead of UpdateWidgetSize to hide various buttons (#14831)

This commit is contained in:
mmtunligit
2025-12-01 17:43:48 +01:00
committed by GitHub
parent 66185a312d
commit e96f35cda9
8 changed files with 31 additions and 30 deletions

View File

@@ -697,6 +697,7 @@ public:
SelectCompanyLiveryWindow(WindowDesc &desc, CompanyID company, GroupID group) : Window(desc)
{
this->CreateNestedTree();
this->GetWidget<NWidgetStacked>(WID_SCL_SEC_COL_DROP_SEL)->SetDisplayedPlane(_loaded_newgrf_features.has_2CC ? 0 : SZSP_NONE);
this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR);
if (group == GroupID::Invalid()) {
@@ -767,10 +768,7 @@ public:
}
case WID_SCL_SEC_COL_DROPDOWN:
if (!_loaded_newgrf_features.has_2CC) {
size.width = 0;
break;
}
if (!_loaded_newgrf_features.has_2CC) break;
[[fallthrough]];
case WID_SCL_PRI_COL_DROPDOWN: {
@@ -1089,7 +1087,9 @@ static constexpr std::initializer_list<NWidgetPart> _nested_select_company_liver
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_GREY, WID_SCL_SPACER_DROPDOWN), SetFill(1, 1), SetResize(1, 0), EndContainer(),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_PRI_COL_DROPDOWN), SetFill(0, 1), SetToolTip(STR_LIVERY_PRIMARY_TOOLTIP),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_SEC_COL_DROPDOWN), SetFill(0, 1), SetToolTip(STR_LIVERY_SECONDARY_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCL_SEC_COL_DROP_SEL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SCL_SEC_COL_DROPDOWN), SetFill(0, 1), SetToolTip(STR_LIVERY_SECONDARY_TOOLTIP),
EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
};

View File

@@ -266,10 +266,12 @@ static constexpr std::initializer_list<NWidgetPart> _nested_small_news_widgets =
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE, WID_N_CLOSEBOX),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_N_CAPTION),
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP),
SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON),
SetResize(1, 0),
SetToolTip(STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_N_SHOW_GROUP_SEL),
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_N_SHOW_GROUP),
SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON),
SetResize(1, 0),
SetToolTip(STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP),
EndContainer(),
EndContainer(),
/* Main part */
@@ -368,8 +370,12 @@ struct NewsWindow : Window {
this->CreateNestedTree();
bool has_vehicle_id = std::holds_alternative<VehicleID>(ni->ref1);
NWidgetStacked *nwid_sel = this->GetWidget<NWidgetStacked>(WID_N_SHOW_GROUP_SEL);
if (nwid_sel != nullptr) nwid_sel->SetDisplayedPlane(has_vehicle_id ? 0 : SZSP_NONE);
NWidgetCore *nwid = this->GetWidget<NWidgetCore>(WID_N_SHOW_GROUP);
if (std::holds_alternative<VehicleID>(ni->ref1) && nwid != nullptr) {
if (has_vehicle_id && nwid != nullptr) {
const Vehicle *v = Vehicle::Get(std::get<VehicleID>(ni->ref1));
switch (v->type) {
case VEH_TRAIN:
@@ -470,14 +476,6 @@ struct NewsWindow : Window {
d2.height += WidgetDimensions::scaled.captiontext.Vertical();
d2.width += WidgetDimensions::scaled.captiontext.Horizontal();
size = d2;
} else {
/* Hide 'Show group window' button if this news is not about a vehicle. */
size.width = 0;
size.height = 0;
resize.width = 0;
resize.height = 0;
fill.width = 0;
fill.height = 0;
}
return;

View File

@@ -838,8 +838,10 @@ static constexpr std::initializer_list<NWidgetPart> _nested_station_view_widgets
NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ACCEPTS_RATINGS), SetMinimalSize(46, 12), SetResize(1, 0), SetFill(1, 1),
SetStringTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
SetStringTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SV_CLOSE_AIRPORT_SEL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
SetStringTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
EndContainer(),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
@@ -1321,6 +1323,7 @@ struct StationViewWindow : public Window {
StationViewWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
{
this->CreateNestedTree();
this->GetWidget<NWidgetStacked>(WID_SV_CLOSE_AIRPORT_SEL)->SetDisplayedPlane(Station::Get(this->window_number)->facilities.Test(StationFacility::Airport) ? 0 : SZSP_NONE);
this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
/* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
this->FinishInitNested(window_number);
@@ -1409,15 +1412,6 @@ struct StationViewWindow : public Window {
case WID_SV_ACCEPT_RATING_LIST:
size.height = ((this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->GetString() == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * GetCharacterHeight(FS_NORMAL) + padding.height;
break;
case WID_SV_CLOSE_AIRPORT:
if (!Station::Get(this->window_number)->facilities.Test(StationFacility::Airport)) {
/* Hide 'Close Airport' button if no airport present. */
size.width = 0;
resize.width = 0;
fill.width = 0;
}
break;
}
}

View File

@@ -2843,8 +2843,10 @@ static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_view_widgets
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_CLONE), SetMinimalSize(18, 18), SetSpriteTip(SPR_EMPTY /* filled later */),
EndContainer(),
/* For trains only, 'ignore signal' button. */
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_FORCE_PROCEED), SetMinimalSize(18, 18),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VV_FORCE_PROCEED_SEL),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_FORCE_PROCEED), SetMinimalSize(18, 18),
SetSpriteTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VV_SELECT_REFIT_TURN),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_REFIT), SetMinimalSize(18, 18), SetSpriteTip(SPR_REFIT_VEHICLE),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_TURN_AROUND), SetMinimalSize(18, 18),
@@ -3017,13 +3019,16 @@ public:
switch (v->type) {
case VEH_TRAIN:
this->GetWidget<NWidgetCore>(WID_VV_TURN_AROUND)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP);
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(0);
break;
case VEH_ROAD:
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(SZSP_NONE);
break;
case VEH_SHIP:
case VEH_AIRCRAFT:
this->GetWidget<NWidgetStacked>(WID_VV_FORCE_PROCEED_SEL)->SetDisplayedPlane(SZSP_NONE);
this->SelectPlane(SEL_RT_REFIT);
break;

View File

@@ -90,6 +90,7 @@ enum SelectCompanyLiveryWidgets : WidgetID {
WID_SCL_SPACER_DROPDOWN, ///< Spacer for dropdown.
WID_SCL_PRI_COL_DROPDOWN, ///< Dropdown for primary colour.
WID_SCL_SEC_COL_DROPDOWN, ///< Dropdown for secondary colour.
WID_SCL_SEC_COL_DROP_SEL, ///< Container for secondary color dropdown, which can be hidden.
WID_SCL_MATRIX, ///< Matrix.
WID_SCL_MATRIX_SCROLLBAR, ///< Matrix scrollbar.
};

View File

@@ -32,6 +32,7 @@ enum NewsWidgets : WidgetID {
WID_N_VEH_SPR, ///< Graphical display of the new vehicle.
WID_N_VEH_INFO, ///< Some technical data of the new vehicle.
WID_N_SHOW_GROUP, ///< Show vehicle's group
WID_N_SHOW_GROUP_SEL, ///< Selector for showing vehicle group, which can be hidden.
};
/** Widgets of the #MessageHistoryWindow class. */

View File

@@ -24,6 +24,7 @@ enum StationViewWidgets : WidgetID {
WID_SV_ACCEPTS_RATINGS, ///< 'Accepts' / 'Ratings' button.
WID_SV_RENAME, ///< 'Rename' button.
WID_SV_CLOSE_AIRPORT, ///< 'Close airport' button.
WID_SV_CLOSE_AIRPORT_SEL, ///< Container for 'close airport' button, which can be hidden.
WID_SV_TRAINS, ///< List of scheduled trains button.
WID_SV_ROADVEHS, ///< List of scheduled road vehs button.
WID_SV_SHIPS, ///< List of scheduled ships button.

View File

@@ -27,6 +27,7 @@ enum VehicleViewWidgets : WidgetID {
WID_VV_SELECT_REFIT_TURN, ///< Selection widget between 'refit' and 'turn around' buttons.
WID_VV_TURN_AROUND, ///< Turn this vehicle around.
WID_VV_FORCE_PROCEED, ///< Force this vehicle to pass a signal at danger.
WID_VV_FORCE_PROCEED_SEL, ///< Container for 'force proceed' button, which can be hidden.
WID_VV_HONK_HORN, ///< Honk the vehicles horn (not drawn on UI, only used for hotkey).
};