Changeset - r28367:98f4e222a258
[Not reviewed]
master
0 3 0
Peter Nelson - 11 months ago 2023-12-30 20:50:01
peter1138@openttd.org
Codechange: Use GetParentWidget to find widget's NWidgetMatrix container.
3 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/object_gui.cpp
Show inline comments
 
@@ -330,13 +330,13 @@ public:
 

	
 
				/* Height of the selection matrix.
 
				 * Depending on the number of views, the matrix has a 1x1, 1x2, 2x1 or 2x2 layout. To make the previews
 
				 * 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
 
				 * 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;
 

	
 
				DrawPixelInfo tmp_dpi;
 
				/* Set up a clipping area for the preview. */
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
@@ -351,13 +351,13 @@ public:
 
				}
 
				break;
 
			}
 

	
 
			case WID_BO_SELECT_IMAGE: {
 
				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;
 
				const ObjectSpec *spec = objclass->GetSpec(obj_index);
 
				if (spec == nullptr) break;
 

	
 
				DrawPixelInfo tmp_dpi;
 
				/* Set up a clipping area for the preview. */
 
@@ -506,20 +506,20 @@ public:
 
				this->SelectFirstAvailableObject(false);
 
				break;
 
			}
 

	
 
			case WID_BO_SELECT_IMAGE: {
 
				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);
 
				break;
 
			}
 

	
 
			case WID_BO_OBJECT_SPRITE:
 
				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.
 
				}
 
				break;
 
		}
 
	}
 

	
src/rail_gui.cpp
Show inline comments
 
@@ -1282,13 +1282,13 @@ public:
 
					statclass++;
 
				}
 
				break;
 
			}
 

	
 
			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);
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
 

	
 
				/* Set up a clipping area for the station preview. */
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
@@ -1467,23 +1467,23 @@ public:
 
				this->SetDirty();
 
				CloseWindowById(WC_SELECT_STATION, 0);
 
				break;
 
			}
 

	
 
			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;
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(y);
 
				if (!IsStationAvailable(statspec)) return;
 

	
 
				_railstation.station_type = y;
 

	
 
				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);
 
				this->SetDirty();
 
				CloseWindowById(WC_SELECT_STATION, 0);
 
				break;
 
			}
 
@@ -2094,13 +2094,13 @@ struct BuildRailWaypointWindow : PickerW
 
	}
 

	
 
	void DrawWidget(const Rect &r, WidgetID widget) const override
 
	{
 
		switch (widget) {
 
			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);
 

	
 
				DrawPixelInfo tmp_dpi;
 
				Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
 
				if (FillDrawPixelInfo(&tmp_dpi, ir)) {
 
					AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
 
@@ -2117,22 +2117,22 @@ struct BuildRailWaypointWindow : PickerW
 
	}
 

	
 
	void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
 
	{
 
		switch (widget) {
 
			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());
 
				uint16_t type = this->list.at(sel);
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = this->waypoints->GetSpec(type);
 
				if (!IsStationAvailable(statspec)) return;
 

	
 
				_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);
 
				this->SetDirty();
 
				break;
 
			}
 
		}
 
	}
src/road_gui.cpp
Show inline comments
 
@@ -1448,13 +1448,13 @@ public:
 
					statclass++;
 
				}
 
				break;
 
			}
 

	
 
			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);
 

	
 
				const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(type);
 
				StationType st = GetRoadStationTypeByWindowClass(this->window_class);
 

	
 
				/* Set up a clipping area for the sprite preview. */
 
@@ -1546,23 +1546,23 @@ public:
 
				this->SetDirty();
 
				CloseWindowById(WC_SELECT_STATION, 0);
 
				break;
 
			}
 

	
 
			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;
 

	
 
				const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(y);
 
				StationType st = GetRoadStationTypeByWindowClass(this->window_class);
 

	
 
				if (!IsRoadStopAvailable(spec, st)) return;
 

	
 
				_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);
 
				this->SetDirty();
 
				CloseWindowById(WC_SELECT_STATION, 0);
 
				this->CheckOrientationValid();
 
				break;
0 comments (0 inline, 0 general)