2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file engine_gui.cpp GUI to show engine related information. */
|
2007-02-23 18:55:07 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-03-31 00:17:39 +00:00
|
|
|
#include "engine_func.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
#include "engine_base.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
|
|
|
#include "economy_func.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static StringID GetEngineCategoryName(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-03 22:03:15 +00:00
|
|
|
switch (GetEngine(engine)->type) {
|
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD: return STR_8103_ROAD_VEHICLE;
|
|
|
|
case VEH_AIRCRAFT: return STR_8104_AIRCRAFT;
|
|
|
|
case VEH_SHIP: return STR_8105_SHIP;
|
|
|
|
case VEH_TRAIN:
|
2007-03-03 22:03:15 +00:00
|
|
|
switch (RailVehInfo(engine)->railtype) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
|
|
|
|
}
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _engine_preview_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
|
2005-10-01 12:43:34 +00:00
|
|
|
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawEngineInfo {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawEngineProc *engine_proc;
|
|
|
|
DrawEngineInfoProc *info_proc;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const DrawEngineInfo _draw_engine_list[4] = {
|
2007-03-03 22:03:15 +00:00
|
|
|
{ DrawTrainEngine, DrawTrainEngineInfo },
|
|
|
|
{ DrawRoadVehEngine, DrawRoadVehEngineInfo },
|
|
|
|
{ DrawShipEngine, DrawShipEngineInfo },
|
|
|
|
{ DrawAircraftEngine, DrawAircraftEngineInfo },
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2005-10-01 12:43:34 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
EngineID engine = w->window_number;
|
2005-11-14 19:48:04 +00:00
|
|
|
const DrawEngineInfo* dei;
|
|
|
|
int width;
|
2005-10-01 12:43:34 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
|
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringCentered(w->width >> 1, 80, STR_ENGINE_NAME, TC_BLACK);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 22:03:15 +00:00
|
|
|
dei = &_draw_engine_list[GetEngine(engine)->type];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
width = w->width;
|
|
|
|
dei->engine_proc(width >> 1, 100, engine, 0);
|
|
|
|
dei->info_proc(engine, width >> 1, 130, width - 52);
|
|
|
|
break;
|
2005-10-01 12:43:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2005-11-14 19:48:04 +00:00
|
|
|
case 4:
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
|
2006-11-18 17:04:44 +00:00
|
|
|
/* Fallthrough */
|
|
|
|
case 3:
|
2005-11-14 19:48:04 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _engine_preview_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 300, 192, 300, 192,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_ENGINE_PREVIEW, WC_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_engine_preview_widgets,
|
|
|
|
EnginePreviewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-11-19 22:24:18 +00:00
|
|
|
AllocateWindowDescFront(&_engine_preview_desc, engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine);
|
2007-10-20 14:51:09 +00:00
|
|
|
int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD) ? 1 : 0;
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
|
2007-02-04 05:53:09 +00:00
|
|
|
SetDParam(2, rvi->max_speed * 10 / 16);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(3, rvi->power << multihead);
|
|
|
|
SetDParam(1, rvi->weight << multihead);
|
|
|
|
|
2008-02-21 19:09:10 +00:00
|
|
|
SetDParam(4, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8 << multihead);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (rvi->capacity != 0) {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(5, rvi->cargo_type);
|
2005-10-23 13:04:44 +00:00
|
|
|
SetDParam(6, rvi->capacity << multihead);
|
|
|
|
} else {
|
2006-10-20 19:48:25 +00:00
|
|
|
SetDParam(5, CT_INVALID);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
2006-03-31 17:40:31 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 5);
|
2007-03-18 10:37:22 +00:00
|
|
|
SetDParam(1, avi->max_speed * 10 / 16);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(2, avi->passenger_capacity);
|
|
|
|
SetDParam(3, avi->mail_capacity);
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RoadVehicleInfo *rvi = RoadVehInfo(engine);
|
|
|
|
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5);
|
2007-02-04 05:53:09 +00:00
|
|
|
SetDParam(1, rvi->max_speed * 10 / 32);
|
2008-02-21 19:09:10 +00:00
|
|
|
SetDParam(2, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(3, rvi->cargo_type);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(4, rvi->capacity);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const ShipVehicleInfo *svi = ShipVehInfo(engine);
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5);
|
2007-02-04 05:53:09 +00:00
|
|
|
SetDParam(1, svi->max_speed * 10 / 32);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(2, svi->cargo_type);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(3, svi->capacity);
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(4, svi->running_cost * _price.ship_running >> 8);
|
2005-07-01 14:05:44 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2007-03-03 22:03:15 +00:00
|
|
|
|
|
|
|
StringID GetNewsStringNewVehicleAvail(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-03 22:03:15 +00:00
|
|
|
EngineID engine = ni->string_id;
|
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(1, engine);
|
2007-03-03 22:03:15 +00:00
|
|
|
return STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-03-28 08:53:36 +00:00
|
|
|
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
2007-03-03 22:03:15 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
2008-03-28 08:53:36 +00:00
|
|
|
EngineID engine = ni->string_id;
|
2007-03-03 22:03:15 +00:00
|
|
|
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
|
|
|
|
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2007-03-03 22:03:15 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 22:03:15 +00:00
|
|
|
dei->engine_proc(w->width >> 1, 88, engine, 0);
|
|
|
|
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
|
|
|
|
dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|