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)
|
BuildRailToolbarWindow(WindowDesc &desc, RailType railtype) : Window(desc)
|
||||||
{
|
{
|
||||||
|
this->railtype = railtype;
|
||||||
this->CreateNestedTree();
|
this->CreateNestedTree();
|
||||||
this->SetupRailToolbar(railtype);
|
|
||||||
this->FinishInitNested(TRANSPORT_RAIL);
|
this->FinishInitNested(TRANSPORT_RAIL);
|
||||||
this->DisableWidget(WID_RAT_REMOVE);
|
this->DisableWidget(WID_RAT_REMOVE);
|
||||||
this->OnInvalidateData();
|
this->OnInvalidateData();
|
||||||
|
@ -490,16 +490,10 @@ struct BuildRailToolbarWindow : Window {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void OnInit() override
|
||||||
* Configures the rail toolbar for railtype given
|
|
||||||
* @param railtype the railtype to display
|
|
||||||
*/
|
|
||||||
void SetupRailToolbar(RailType railtype)
|
|
||||||
{
|
{
|
||||||
this->railtype = railtype;
|
/* Configure the rail toolbar for the railtype. */
|
||||||
const RailTypeInfo *rti = GetRailTypeInfo(railtype);
|
const RailTypeInfo *rti = GetRailTypeInfo(this->railtype);
|
||||||
|
|
||||||
assert(railtype < RAILTYPE_END);
|
|
||||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail;
|
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_X)->widget_data = rti->gui_sprites.build_x_rail;
|
||||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_EW)->widget_data = rti->gui_sprites.build_ew_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)
|
void ModifyRailType(RailType railtype)
|
||||||
{
|
{
|
||||||
this->SetupRailToolbar(railtype);
|
this->railtype = railtype;
|
||||||
this->ReInit();
|
this->ReInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,9 +347,8 @@ struct BuildRoadToolbarWindow : Window {
|
||||||
|
|
||||||
BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
|
BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
|
||||||
{
|
{
|
||||||
this->Initialize(_cur_roadtype);
|
this->roadtype = _cur_roadtype;
|
||||||
this->CreateNestedTree();
|
this->CreateNestedTree();
|
||||||
this->SetupRoadToolbar();
|
|
||||||
this->FinishInitNested(window_number);
|
this->FinishInitNested(window_number);
|
||||||
this->SetWidgetDisabledState(WID_ROT_REMOVE, true);
|
this->SetWidgetDisabledState(WID_ROT_REMOVE, true);
|
||||||
|
|
||||||
|
@ -409,18 +408,9 @@ struct BuildRoadToolbarWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize(RoadType roadtype)
|
void OnInit() override
|
||||||
{
|
|
||||||
assert(roadtype < ROADTYPE_END);
|
|
||||||
this->roadtype = roadtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the road toolbar for roadtype given
|
|
||||||
* @param roadtype the roadtype to display
|
|
||||||
*/
|
|
||||||
void SetupRoadToolbar()
|
|
||||||
{
|
{
|
||||||
|
/* Configure the road toolbar for the roadtype. */
|
||||||
const RoadTypeInfo *rti = GetRoadTypeInfo(this->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_X)->widget_data = rti->gui_sprites.build_x_road;
|
||||||
this->GetWidget<NWidgetCore>(WID_ROT_ROAD_Y)->widget_data = rti->gui_sprites.build_y_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)
|
void ModifyRoadType(RoadType roadtype)
|
||||||
{
|
{
|
||||||
this->Initialize(roadtype);
|
this->roadtype = roadtype;
|
||||||
this->SetupRoadToolbar();
|
|
||||||
this->ReInit();
|
this->ReInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue