src/build_vehicle_gui.cpp
changeset 6711 02a4b7b630bc
parent 6710 a08fcbe81983
child 6712 d100bbf7f752
equal deleted inserted replaced
6710:a08fcbe81983 6711:02a4b7b630bc
    39 	BUILD_VEHICLE_WIDGET_SCROLLBAR,
    39 	BUILD_VEHICLE_WIDGET_SCROLLBAR,
    40 	BUILD_VEHICLE_WIDGET_PANEL,
    40 	BUILD_VEHICLE_WIDGET_PANEL,
    41 	BUILD_VEHICLE_WIDGET_BUILD,
    41 	BUILD_VEHICLE_WIDGET_BUILD,
    42 	BUILD_VEHICLE_WIDGET_RENAME,
    42 	BUILD_VEHICLE_WIDGET_RENAME,
    43 	BUILD_VEHICLE_WIDGET_RESIZE,
    43 	BUILD_VEHICLE_WIDGET_RESIZE,
       
    44 	BUILD_VEHICLE_WIDGET_END
    44 };
    45 };
    45 
    46 
    46 static const Widget _build_vehicle_widgets[] = {
    47 static const Widget _build_vehicle_widgets[] = {
    47 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    48 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
    48 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
    49 	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
   525 /**
   526 /**
   526  * Draw the purchase info details of a vehicle at a given location.
   527  * Draw the purchase info details of a vehicle at a given location.
   527  * @param x,y location where to draw the info
   528  * @param x,y location where to draw the info
   528  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
   529  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
   529  * @param engine_number the engine of which to draw the info of
   530  * @param engine_number the engine of which to draw the info of
       
   531  * @return y after drawing all the text
   530  */
   532  */
   531 void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
   533 int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
   532 {
   534 {
   533 	const Engine *e = GetEngine(engine_number);
   535 	const Engine *e = GetEngine(engine_number);
   534 	YearMonthDay ymd;
   536 	YearMonthDay ymd;
   535 	ConvertDateToYMD(e->intro_date, &ymd);
   537 	ConvertDateToYMD(e->intro_date, &ymd);
   536 	bool refitable = false;
   538 	bool refitable = false;
   592 	}
   594 	}
   593 
   595 
   594 	/* Additional text from NewGRF */
   596 	/* Additional text from NewGRF */
   595 	y += ShowAdditionalText(x, y, w, engine_number);
   597 	y += ShowAdditionalText(x, y, w, engine_number);
   596 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
   598 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
       
   599 
       
   600 	return y;
   597 }
   601 }
   598 
   602 
   599 /* Figure out what train EngineIDs to put in the list */
   603 /* Figure out what train EngineIDs to put in the list */
   600 static void GenerateBuildTrainList(Window *w)
   604 static void GenerateBuildTrainList(Window *w)
   601 {
   605 {
   791 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   795 			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
   792 		}
   796 		}
   793 	}
   797 	}
   794 }
   798 }
   795 
   799 
       
   800 static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
       
   801 {
       
   802 	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
       
   803 
       
   804 	SetWindowDirty(w);
       
   805 	wi->bottom += expand_by;
       
   806 
       
   807 	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
       
   808 		wi = &w->widget[i];
       
   809 		wi->top += expand_by;
       
   810 		wi->bottom += expand_by;
       
   811 	}
       
   812 
       
   813 	w->height += expand_by;
       
   814 	SetWindowDirty(w);
       
   815 }
       
   816 
   796 static void DrawBuildVehicleWindow(Window *w)
   817 static void DrawBuildVehicleWindow(Window *w)
   797 {
   818 {
   798 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
   819 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
   799 	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
   820 	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
   800 
   821 
   806 
   827 
   807 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
   828 	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false);
   808 
   829 
   809 	if (bv->sel_engine != INVALID_ENGINE) {
   830 	if (bv->sel_engine != INVALID_ENGINE) {
   810 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   831 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
   811 		DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
   832 		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
       
   833 
       
   834 		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
   812 	}
   835 	}
   813 
   836 
   814 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
   837 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
   815 	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
   838 	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
   816 }
   839 }