Changeset - r12828:1411e13c41d0
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-08-30 18:41:03
alberth@openttd.org
(svn r17328) -Codechange: Get the vehicle technical data as string rather than having it printed.
2 files changed with 42 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/engine_gui.cpp
Show inline comments
 
@@ -76,24 +76,6 @@ static const NWidgetPart _nested_engine_
 
	EndContainer(),
 
};
 

	
 
typedef void DrawEngineInfoProc(EngineID, int left, int right, int top, int bottom);
 

	
 
struct DrawEngineInfo {
 
	DrawEngineInfoProc *info_proc;
 
};
 

	
 
static void DrawTrainEngineInfo(EngineID engine, int left, int right, int top, int bottom);
 
static void DrawRoadVehEngineInfo(EngineID engine, int left, int right, int top, int bottom);
 
static void DrawShipEngineInfo(EngineID engine, int left, int right, int top, int bottom);
 
static void DrawAircraftEngineInfo(EngineID engine, int left, int right, int top, int bottom);
 

	
 
static const DrawEngineInfo _draw_engine_list[4] = {
 
	{ DrawTrainEngineInfo    },
 
	{ DrawRoadVehEngineInfo  },
 
	{ DrawShipEngineInfo     },
 
	{ DrawAircraftEngineInfo },
 
};
 

	
 
struct EnginePreviewWindow : Window {
 
	EnginePreviewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
@@ -111,11 +93,9 @@ struct EnginePreviewWindow : Window {
 
		SetDParam(0, engine);
 
		DrawString(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 80, STR_ENGINE_NAME, TC_BLACK, SA_CENTER);
 

	
 
		const DrawEngineInfo *dei = &_draw_engine_list[Engine::Get(engine)->type];
 

	
 
		int width = this->width;
 
		DrawVehicleEngine(width >> 1, 100, engine, GetEnginePalette(engine, _local_company));
 
		dei->info_proc(engine, this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 170);
 
		DrawStringMultiLine(this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 170, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
@@ -156,10 +136,8 @@ uint GetTotalCapacityOfArticulatedParts(
 
	return total;
 
}
 

	
 
static void DrawTrainEngineInfo(EngineID engine, int left, int right, int top, int bottom)
 
static StringID GetTrainEngineInfoString(const Engine *e)
 
{
 
	const Engine *e = Engine::Get(engine);
 

	
 
	SetDParam(0, e->GetCost());
 
	SetDParam(2, e->GetDisplayMaxSpeed());
 
	SetDParam(3, e->GetPower());
 
@@ -167,19 +145,18 @@ static void DrawTrainEngineInfo(EngineID
 

	
 
	SetDParam(4, e->GetRunningCost());
 

	
 
	uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_TRAIN);
 
	uint capacity = GetTotalCapacityOfArticulatedParts(e->index, VEH_TRAIN);
 
	if (capacity != 0) {
 
		SetDParam(5, e->GetDefaultCargoType());
 
		SetDParam(6, capacity);
 
	} else {
 
		SetDParam(5, CT_INVALID);
 
	}
 
	DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER, TC_FROMSTRING, SA_CENTER);
 
	return STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER;
 
}
 

	
 
static void DrawAircraftEngineInfo(EngineID engine, int left, int right, int top, int bottom)
 
static StringID GetAircraftEngineInfoString(const Engine *e)
 
{
 
	const Engine *e = Engine::Get(engine);
 
	CargoID cargo = e->GetDefaultCargoType();
 

	
 
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
 
@@ -190,26 +167,22 @@ static void DrawAircraftEngineInfo(Engin
 
		SetDParam(4, CT_MAIL),
 
		SetDParam(5, e->u.air.mail_capacity);
 
		SetDParam(6, e->GetRunningCost());
 

	
 
		DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_CAPACITY_RUNCOST, TC_FROMSTRING, SA_CENTER);
 
		return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_CAPACITY_RUNCOST;
 
	} else {
 
		SetDParam(0, e->GetCost());
 
		SetDParam(1, e->GetDisplayMaxSpeed());
 
		SetDParam(2, cargo);
 
		SetDParam(3, e->GetDisplayDefaultCapacity());
 
		SetDParam(4, e->GetRunningCost());
 

	
 
		DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST, TC_FROMSTRING, SA_CENTER);
 
		return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST;
 
	}
 
}
 

	
 
static void DrawRoadVehEngineInfo(EngineID engine, int left, int right, int top, int bottom)
 
static StringID GetRoadVehEngineInfoString(const Engine *e)
 
{
 
	const Engine *e = Engine::Get(engine);
 

	
 
	SetDParam(0, e->GetCost());
 
	SetDParam(1, e->GetDisplayMaxSpeed());
 
	uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_ROAD);
 
	uint capacity = GetTotalCapacityOfArticulatedParts(e->index, VEH_ROAD);
 
	if (capacity != 0) {
 
		SetDParam(2, e->GetDefaultCargoType());
 
		SetDParam(3, capacity);
 
@@ -217,20 +190,45 @@ static void DrawRoadVehEngineInfo(Engine
 
		SetDParam(2, CT_INVALID);
 
	}
 
	SetDParam(4, e->GetRunningCost());
 

	
 
	DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST, TC_FROMSTRING, SA_CENTER);
 
	return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST;
 
}
 

	
 
static void DrawShipEngineInfo(EngineID engine, int left, int right, int top, int bottom)
 
static StringID GetShipEngineInfoString(const Engine *e)
 
{
 
	const Engine *e = Engine::Get(engine);
 

	
 
	SetDParam(0, e->GetCost());
 
	SetDParam(1, e->GetDisplayMaxSpeed());
 
	SetDParam(2, e->GetDefaultCargoType());
 
	SetDParam(3, e->GetDisplayDefaultCapacity());
 
	SetDParam(4, e->GetRunningCost());
 
	DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST, TC_FROMSTRING, SA_CENTER);
 
	return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST;
 
}
 

	
 

	
 
/**
 
 * Get a multi-line string with some technical data, describing the engine.
 
 * @param engine Engine to describe.
 
 * @return String describing the engine.
 
 * @post \c DParam array is set up for printing the string.
 
 */
 
StringID GetEngineInfoString(EngineID engine)
 
{
 
	const Engine *e = Engine::Get(engine);
 

	
 
	switch (e->type) {
 
		case VEH_TRAIN:
 
			return GetTrainEngineInfoString(e);
 

	
 
		case VEH_ROAD:
 
			return GetRoadVehEngineInfoString(e);
 

	
 
		case VEH_SHIP:
 
			return GetShipEngineInfoString(e);
 

	
 
		case VEH_AIRCRAFT:
 
			return GetAircraftEngineInfoString(e);
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
@@ -269,7 +267,6 @@ void DrawNewsNewVehicleAvail(Window *w, 
 
{
 
	assert(ni->reftype1 == NR_ENGINE);
 
	EngineID engine = ni->ref1;
 
	const DrawEngineInfo *dei = &_draw_engine_list[Engine::Get(engine)->type];
 

	
 
	SetDParam(0, GetEngineCategoryName(engine));
 
	DrawStringMultiLine(1, w->width - 2, 0, 56, STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE, TC_FROMSTRING, SA_CENTER);
 
@@ -281,7 +278,7 @@ void DrawNewsNewVehicleAvail(Window *w, 
 

	
 
	DrawVehicleEngine(w->width >> 1, 88, engine, GetEnginePalette(engine, _local_company));
 
	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
 
	dei->info_proc(engine, 26, w->width - 26, 100, 170);
 
	DrawStringMultiLine(26, w->width - 26, 100, 170, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
 
}
 

	
 

	
src/engine_gui.h
Show inline comments
 
@@ -21,6 +21,7 @@ void EngList_Sort(GUIEngineList *el, Eng
 
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
 

	
 
StringID GetEngineCategoryName(EngineID engine);
 
StringID GetEngineInfoString(EngineID engine);
 
void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal);
 

	
 
#endif /* ENGINE_GUI_H */
0 comments (0 inline, 0 general)