734 * @param min where to start in the list |
734 * @param min where to start in the list |
735 * @param max where in the list to end |
735 * @param max where in the list to end |
736 * @param selected_id what engine to highlight as selected, if any |
736 * @param selected_id what engine to highlight as selected, if any |
737 * @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off |
737 * @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off |
738 */ |
738 */ |
739 void DrawEngineList(VehicleType type, int x, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group) |
739 void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group) |
740 { |
740 { |
741 byte step_size = GetVehicleListHeight(type); |
741 byte step_size = GetVehicleListHeight(type); |
742 byte x_offset = 0; |
742 byte x_offset = 0; |
743 byte y_offset = 0; |
743 byte y_offset = 0; |
744 |
744 |
767 y_offset = 3; |
767 y_offset = 3; |
768 break; |
768 break; |
769 default: NOT_REACHED(); |
769 default: NOT_REACHED(); |
770 } |
770 } |
771 |
771 |
|
772 uint maxw = r - x - x_offset; |
|
773 |
772 for (; min < max; min++, y += step_size) { |
774 for (; min < max; min++, y += step_size) { |
773 const EngineID engine = (*eng_list)[min]; |
775 const EngineID engine = (*eng_list)[min]; |
774 /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */ |
776 /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */ |
775 const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine); |
777 const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine); |
776 |
778 |
777 SetDParam(0, engine); |
779 SetDParam(0, engine); |
778 DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK); |
780 DrawStringTruncated(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, maxw); |
779 DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player)); |
781 DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player)); |
780 if (count_location != 0) { |
782 if (count_location != 0) { |
781 SetDParam(0, num_engines); |
783 SetDParam(0, num_engines); |
782 DrawStringRightAligned(count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING); |
784 DrawStringRightAligned(count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING); |
783 } |
785 } |
1116 /* Set text of sort by dropdown */ |
1118 /* Set text of sort by dropdown */ |
1117 this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria]; |
1119 this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria]; |
1118 |
1120 |
1119 this->DrawWidgets(); |
1121 this->DrawWidgets(); |
1120 |
1122 |
1121 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); |
1123 DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].right, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP); |
1122 |
1124 |
1123 if (this->sel_engine != INVALID_ENGINE) { |
1125 if (this->sel_engine != INVALID_ENGINE) { |
1124 const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL]; |
1126 const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL]; |
1125 int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine); |
1127 int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine); |
1126 |
1128 |