721 } |
721 } |
722 _internal_sort_order = bv->descending_sort_order; |
722 _internal_sort_order = bv->descending_sort_order; |
723 EngList_Sort(&bv->eng_list, _sorter[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria]); |
723 EngList_Sort(&bv->eng_list, _sorter[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria]); |
724 } |
724 } |
725 |
725 |
|
726 static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal) |
|
727 { |
|
728 switch (type) { |
|
729 case VEH_Train: DrawTrainEngine( x, y, engine, pal); break; |
|
730 case VEH_Road: DrawRoadVehEngine( x, y, engine, pal); break; |
|
731 case VEH_Ship: DrawShipEngine( x, y, engine, pal); break; |
|
732 case VEH_Aircraft: DrawAircraftEngine(x, y, engine, pal); break; |
|
733 default: NOT_REACHED(); |
|
734 } |
|
735 } |
|
736 |
|
737 /** Engine drawing loop |
|
738 * @param type Type of vehicle (VEH_*) |
|
739 * @param x,y Where should the list start |
|
740 * @param eng_list What engines to draw |
|
741 * @param min where to start in the list |
|
742 * @param max where in the list to end. MAKE SURE THAT THIS IS NOT LONGER THAN THE ENGINE LIST ITSELF! |
|
743 * @param selected_id what engine to highlight as selected, if any |
|
744 */ |
|
745 static void DrawEngineList(byte type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id) |
|
746 { |
|
747 byte step_size = GetVehicleListHeight(type); |
|
748 byte x_offset = 0; |
|
749 byte y_offset = 0; |
|
750 |
|
751 switch (type) { |
|
752 case VEH_Train: |
|
753 x++; // train and road vehicles use the same offset, except trains are one more pixel to the right |
|
754 /* Fallthough */ |
|
755 case VEH_Road: |
|
756 x += 26; |
|
757 x_offset = 30; |
|
758 y += 2; |
|
759 y_offset = 4; |
|
760 break; |
|
761 case VEH_Ship: |
|
762 x += 35; |
|
763 x_offset = 40; |
|
764 y += 7; |
|
765 y_offset = 3; |
|
766 break; |
|
767 case VEH_Aircraft: |
|
768 x += 27; |
|
769 x_offset = 33; |
|
770 y += 7; |
|
771 y_offset = 3; |
|
772 break; |
|
773 default: NOT_REACHED(); |
|
774 } |
|
775 |
|
776 for (; min < max; min++, y += step_size) { |
|
777 const EngineID engine = eng_list[min]; |
|
778 |
|
779 DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); |
|
780 DrawVehicleEngine(type, x, y + y_offset, engine, GetEnginePalette(engine, _local_player)); |
|
781 } |
|
782 } |
|
783 |
726 static void DrawBuildVehicleWindow(Window *w) |
784 static void DrawBuildVehicleWindow(Window *w) |
727 { |
785 { |
728 const buildvehicle_d *bv = &WP(w, buildvehicle_d); |
786 const buildvehicle_d *bv = &WP(w, buildvehicle_d); |
|
787 uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list)); |
729 |
788 |
730 SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0); |
789 SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0); |
731 |
790 |
732 SetVScrollCount(w, EngList_Count(&bv->eng_list)); |
791 SetVScrollCount(w, EngList_Count(&bv->eng_list)); |
733 SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles |
792 SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles |
734 DrawWindowWidgets(w); |
793 DrawWindowWidgets(w); |
735 |
794 |
736 { |
795 DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine); |
737 int x = 2; |
796 |
738 int y = 27; |
797 if (bv->sel_engine != INVALID_ENGINE) { |
739 EngineID selected_id = bv->sel_engine; |
798 const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL]; |
740 uint16 position = w->vscroll.pos; |
799 DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine); |
741 uint16 max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list)); |
800 } |
742 |
801 |
743 switch (bv->vehicle_type) { |
|
744 case VEH_Train: |
|
745 for (; position < max; position++, y += 14) { |
|
746 const EngineID engine = bv->eng_list[position]; |
|
747 |
|
748 DrawString(x + 59, y + 2, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); |
|
749 DrawTrainEngine(x + 29, y + 6, engine, GetEnginePalette(engine, _local_player)); |
|
750 } |
|
751 break; |
|
752 case VEH_Road: |
|
753 for (; position < max; position++, y += 14) { |
|
754 const EngineID engine = bv->eng_list[position]; |
|
755 |
|
756 DrawString(x + 58, y + 2, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); |
|
757 DrawRoadVehEngine(x + 28, y + 6, engine, GetEnginePalette(engine, _local_player)); |
|
758 } |
|
759 break; |
|
760 case VEH_Ship: |
|
761 for (; position < max; position++, y += 24) { |
|
762 const EngineID engine = bv->eng_list[position]; |
|
763 |
|
764 DrawString(x + 75, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); |
|
765 DrawShipEngine(x + 35, y + 10, engine, GetEnginePalette(engine, _local_player)); |
|
766 } |
|
767 break; |
|
768 case VEH_Aircraft: |
|
769 for (; position < max; position++, y += 24) { |
|
770 const EngineID engine = bv->eng_list[position]; |
|
771 |
|
772 DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10); |
|
773 DrawAircraftEngine(x + 29, y + 10, engine, GetEnginePalette(engine, _local_player)); |
|
774 } |
|
775 break; |
|
776 } |
|
777 |
|
778 if (selected_id != INVALID_ENGINE) { |
|
779 const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL]; |
|
780 DrawVehiclePurchaseInfo(x, wi->top + 1, wi->right - wi->left - 2, selected_id); |
|
781 } |
|
782 } |
|
783 DrawString(85, 15, _sort_listing[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria], 0x10); |
802 DrawString(85, 15, _sort_listing[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria], 0x10); |
784 DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10); |
803 DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10); |
785 } |
804 } |
786 |
805 |
787 static void BuildVehicleClickEvent(Window *w, WindowEvent *e) |
806 static void BuildVehicleClickEvent(Window *w, WindowEvent *e) |