src/build_vehicle_gui.cpp
changeset 9395 003c5b8d2931
parent 9380 62dabf4a5b7e
child 9403 8cfca59c11f1
equal deleted inserted replaced
9394:019d83716697 9395:003c5b8d2931
   743  * @param min where to start in the list
   743  * @param min where to start in the list
   744  * @param max where in the list to end
   744  * @param max where in the list to end
   745  * @param selected_id what engine to highlight as selected, if any
   745  * @param selected_id what engine to highlight as selected, if any
   746  * @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off
   746  * @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off
   747  */
   747  */
   748 void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
   748 void DrawEngineList(VehicleType type, int x, int y, const EngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
   749 {
   749 {
   750 	byte step_size = GetVehicleListHeight(type);
   750 	byte step_size = GetVehicleListHeight(type);
   751 	byte x_offset = 0;
   751 	byte x_offset = 0;
   752 	byte y_offset = 0;
   752 	byte y_offset = 0;
   753 
   753 
   754 	assert(max <= eng_list.size());
   754 	assert(max <= eng_list->size());
   755 
   755 
   756 	switch (type) {
   756 	switch (type) {
   757 		case VEH_TRAIN:
   757 		case VEH_TRAIN:
   758 			x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
   758 			x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
   759 			/* Fallthough */
   759 			/* Fallthough */
   777 			break;
   777 			break;
   778 		default: NOT_REACHED();
   778 		default: NOT_REACHED();
   779 	}
   779 	}
   780 
   780 
   781 	for (; min < max; min++, y += step_size) {
   781 	for (; min < max; min++, y += step_size) {
   782 		const EngineID engine = eng_list[min];
   782 		const EngineID engine = (*eng_list)[min];
   783 		/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
   783 		/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
   784 		const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
   784 		const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
   785 
   785 
   786 		SetDParam(0, engine);
   786 		SetDParam(0, engine);
   787 		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
   787 		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
  1115 		/* Set text of sort by dropdown */
  1115 		/* Set text of sort by dropdown */
  1116 		this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria];
  1116 		this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria];
  1117 
  1117 
  1118 		this->DrawWidgets();
  1118 		this->DrawWidgets();
  1119 
  1119 
  1120 		DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
  1120 		DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
  1121 
  1121 
  1122 		if (this->sel_engine != INVALID_ENGINE) {
  1122 		if (this->sel_engine != INVALID_ENGINE) {
  1123 			const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];
  1123 			const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];
  1124 			int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine);
  1124 			int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine);
  1125 
  1125