1
0
Fork 0

Codechange: Use GetParentWidget to find widget's NWidgetMatrix container.

pull/11660/head
Peter Nelson 2023-12-30 20:50:01 +00:00 committed by Peter Nelson
parent c2c65d66ba
commit 628092f133
3 changed files with 13 additions and 13 deletions

View File

@ -333,7 +333,7 @@ public:
* look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger * look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger
* previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle * previews in the layouts with less views we add space homogeneously on all sides, so the 4x4 preview-rectangle
* is centered in the 2x1, 1x2 resp. 1x1 buttons. */ * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
const NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX); const NWidgetMatrix *matrix = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>();
uint matrix_height = matrix->current_y; uint matrix_height = matrix->current_y;
DrawPixelInfo tmp_dpi; DrawPixelInfo tmp_dpi;
@ -354,7 +354,7 @@ public:
case WID_BO_SELECT_IMAGE: { case WID_BO_SELECT_IMAGE: {
ObjectClass *objclass = ObjectClass::Get(_selected_object_class); ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
int obj_index = objclass->GetIndexFromUI(this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->GetCurrentElement()); int obj_index = objclass->GetIndexFromUI(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement());
if (obj_index < 0) break; if (obj_index < 0) break;
const ObjectSpec *spec = objclass->GetSpec(obj_index); const ObjectSpec *spec = objclass->GetSpec(obj_index);
if (spec == nullptr) break; if (spec == nullptr) break;
@ -509,14 +509,14 @@ public:
case WID_BO_SELECT_IMAGE: { case WID_BO_SELECT_IMAGE: {
ObjectClass *objclass = ObjectClass::Get(_selected_object_class); ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
int num_clicked = objclass->GetIndexFromUI(this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->GetCurrentElement()); int num_clicked = objclass->GetIndexFromUI(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement());
if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked); if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
break; break;
} }
case WID_BO_OBJECT_SPRITE: case WID_BO_OBJECT_SPRITE:
if (_selected_object_index != -1) { if (_selected_object_index != -1) {
_selected_object_view = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->GetCurrentElement(); _selected_object_view = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view. this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view.
} }
break; break;

View File

@ -1285,7 +1285,7 @@ public:
} }
case WID_BRAS_IMAGE: { case WID_BRAS_IMAGE: {
uint16_t type = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->GetCurrentElement(); uint16_t type = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
assert(type < _railstation.station_count); assert(type < _railstation.station_count);
/* Check station availability callback */ /* Check station availability callback */
const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type); const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
@ -1470,7 +1470,7 @@ public:
} }
case WID_BRAS_IMAGE: { case WID_BRAS_IMAGE: {
uint16_t y = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->GetCurrentElement(); uint16_t y = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
if (y >= _railstation.station_count) return; if (y >= _railstation.station_count) return;
/* Check station availability callback */ /* Check station availability callback */
@ -1480,7 +1480,7 @@ public:
_railstation.station_type = y; _railstation.station_type = y;
this->CheckSelectedSize(statspec); this->CheckSelectedSize(statspec);
this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->SetClicked(_railstation.station_type); this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->SetClicked(_railstation.station_type);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
this->SetDirty(); this->SetDirty();
@ -2097,7 +2097,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
{ {
switch (widget) { switch (widget) {
case WID_BRW_WAYPOINT: { case WID_BRW_WAYPOINT: {
uint16_t type = this->list.at(this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->GetCurrentElement()); uint16_t type = this->list.at(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement());
const StationSpec *statspec = this->waypoints->GetSpec(type); const StationSpec *statspec = this->waypoints->GetSpec(type);
DrawPixelInfo tmp_dpi; DrawPixelInfo tmp_dpi;
@ -2120,7 +2120,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
{ {
switch (widget) { switch (widget) {
case WID_BRW_WAYPOINT: { case WID_BRW_WAYPOINT: {
uint16_t sel = this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->GetCurrentElement(); uint16_t sel = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
assert(sel < this->list.size()); assert(sel < this->list.size());
uint16_t type = this->list.at(sel); uint16_t type = this->list.at(sel);
@ -2129,7 +2129,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
if (!IsStationAvailable(statspec)) return; if (!IsStationAvailable(statspec)) return;
_cur_waypoint_type = type; _cur_waypoint_type = type;
this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(sel); this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->SetClicked(sel);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
this->SetDirty(); this->SetDirty();
break; break;

View File

@ -1451,7 +1451,7 @@ public:
} }
case WID_BROS_IMAGE: { case WID_BROS_IMAGE: {
uint16_t type = this->GetWidget<NWidgetMatrix>(WID_BROS_MATRIX)->GetCurrentElement(); uint16_t type = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
assert(type < _roadstop_gui_settings.roadstop_count); assert(type < _roadstop_gui_settings.roadstop_count);
const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(type); const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(type);
@ -1549,7 +1549,7 @@ public:
} }
case WID_BROS_IMAGE: { case WID_BROS_IMAGE: {
uint16_t y = this->GetWidget<NWidgetMatrix>(WID_BROS_MATRIX)->GetCurrentElement(); uint16_t y = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement();
if (y >= _roadstop_gui_settings.roadstop_count) return; if (y >= _roadstop_gui_settings.roadstop_count) return;
const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(y); const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(y);
@ -1559,7 +1559,7 @@ public:
_roadstop_gui_settings.roadstop_type = y; _roadstop_gui_settings.roadstop_type = y;
this->GetWidget<NWidgetMatrix>(WID_BROS_MATRIX)->SetClicked(_roadstop_gui_settings.roadstop_type); this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->SetClicked(_roadstop_gui_settings.roadstop_type);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
this->SetDirty(); this->SetDirty();