mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Set up rail/road toolbar buttons during window's OnInit event.
This ensures the buttons are configured without extra initialisation methods.pull/13048/head
parent
0e3fdfb1b5
commit
6d2b93d3b3
|
@ -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<NWidgetCore>(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_X)->widget_data = rti->gui_sprites.build_x_rail;
|
||||
this->GetWidget<NWidgetCore>(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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<NWidgetCore>(WID_ROT_ROAD_X)->widget_data = rti->gui_sprites.build_x_road;
|
||||
this->GetWidget<NWidgetCore>(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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue