From 6d2b93d3b3a6bb6058e8009616f1ff8ecea08114 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 22 Oct 2024 23:48:13 +0100 Subject: [PATCH] Codechange: Set up rail/road toolbar buttons during window's OnInit event. This ensures the buttons are configured without extra initialisation methods. --- src/rail_gui.cpp | 16 +++++----------- src/road_gui.cpp | 19 ++++--------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 0177547305..4dd7d39ada 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -438,8 +438,8 @@ struct BuildRailToolbarWindow : Window { BuildRailToolbarWindow(WindowDesc &desc, RailType railtype) : Window(desc) { + this->railtype = railtype; this->CreateNestedTree(); - this->SetupRailToolbar(railtype); this->FinishInitNested(TRANSPORT_RAIL); this->DisableWidget(WID_RAT_REMOVE); this->OnInvalidateData(); @@ -490,16 +490,10 @@ struct BuildRailToolbarWindow : Window { return true; } - /** - * Configures the rail toolbar for railtype given - * @param railtype the railtype to display - */ - void SetupRailToolbar(RailType railtype) + void OnInit() override { - this->railtype = railtype; - const RailTypeInfo *rti = GetRailTypeInfo(railtype); - - assert(railtype < RAILTYPE_END); + /* Configure the rail toolbar for the railtype. */ + const RailTypeInfo *rti = GetRailTypeInfo(this->railtype); this->GetWidget(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail; this->GetWidget(WID_RAT_BUILD_X)->widget_data = rti->gui_sprites.build_x_rail; this->GetWidget(WID_RAT_BUILD_EW)->widget_data = rti->gui_sprites.build_ew_rail; @@ -516,7 +510,7 @@ struct BuildRailToolbarWindow : Window { */ void ModifyRailType(RailType railtype) { - this->SetupRailToolbar(railtype); + this->railtype = railtype; this->ReInit(); } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index c5bb6d8d50..db299a53ad 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -347,9 +347,8 @@ struct BuildRoadToolbarWindow : Window { BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc) { - this->Initialize(_cur_roadtype); + this->roadtype = _cur_roadtype; this->CreateNestedTree(); - this->SetupRoadToolbar(); this->FinishInitNested(window_number); this->SetWidgetDisabledState(WID_ROT_REMOVE, true); @@ -409,18 +408,9 @@ struct BuildRoadToolbarWindow : Window { } } - void Initialize(RoadType roadtype) - { - assert(roadtype < ROADTYPE_END); - this->roadtype = roadtype; - } - - /** - * Configures the road toolbar for roadtype given - * @param roadtype the roadtype to display - */ - void SetupRoadToolbar() + void OnInit() override { + /* Configure the road toolbar for the roadtype. */ const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype); this->GetWidget(WID_ROT_ROAD_X)->widget_data = rti->gui_sprites.build_x_road; this->GetWidget(WID_ROT_ROAD_Y)->widget_data = rti->gui_sprites.build_y_road; @@ -438,8 +428,7 @@ struct BuildRoadToolbarWindow : Window { */ void ModifyRoadType(RoadType roadtype) { - this->Initialize(roadtype); - this->SetupRoadToolbar(); + this->roadtype = roadtype; this->ReInit(); }