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"
|
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"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "news_type.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"
|
2008-05-27 12:24:23 +00:00
|
|
|
#include "engine_gui.h"
|
2008-06-20 07:23:00 +00:00
|
|
|
#include "articulated_vehicles.h"
|
2008-08-24 21:31:24 +00:00
|
|
|
#include "rail.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
|
|
|
|
2008-05-13 10:17:04 +00:00
|
|
|
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:
|
2008-08-24 21:31:24 +00:00
|
|
|
return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco;
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _engine_preview_widgets[] = {
|
2008-07-30 16:13:58 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_LIGHT_BLUE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_LIGHT_BLUE, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_LIGHT_BLUE, 0, 299, 14, 191, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_LIGHT_BLUE, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_LIGHT_BLUE, 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
|
|
|
};
|
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
struct EnginePreviewWindow : Window {
|
|
|
|
EnginePreviewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-05-23 23:02:13 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-05-18 20:49:22 +00:00
|
|
|
}
|
2005-10-01 12:43:34 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
EngineID engine = this->window_number;
|
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);
|
2008-05-18 20:49:22 +00:00
|
|
|
DrawStringCentered(this->width >> 1, 80, STR_ENGINE_NAME, TC_BLACK);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
int width = this->width;
|
2004-08-09 17:04:08 +00:00
|
|
|
dei->engine_proc(width >> 1, 100, engine, 0);
|
|
|
|
dei->info_proc(engine, width >> 1, 130, width - 52);
|
2005-10-01 12:43:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-18 20:49:22 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2005-11-14 19:48:04 +00:00
|
|
|
case 4:
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, this->window_number, 0, CMD_WANT_ENGINE_PREVIEW);
|
2006-11-18 17:04:44 +00:00
|
|
|
/* Fallthrough */
|
|
|
|
case 3:
|
2008-05-18 20:49:22 +00:00
|
|
|
delete this;
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-18 20:49:22 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
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,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_CONSTRUCTION,
|
2009-03-15 15:12:06 +00:00
|
|
|
_engine_preview_widgets
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-18 20:49:22 +00:00
|
|
|
AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type)
|
2008-06-20 07:23:00 +00:00
|
|
|
{
|
|
|
|
uint total = 0;
|
|
|
|
|
|
|
|
uint16 *cap = GetCapacityOfArticulatedParts(engine, type);
|
|
|
|
for (uint c = 0; c < NUM_CARGO; c++) {
|
|
|
|
total += cap[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
const Engine *e = GetEngine(engine);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(2, e->GetDisplayMaxSpeed());
|
|
|
|
SetDParam(3, e->GetPower());
|
|
|
|
SetDParam(1, e->GetDisplayWeight());
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(4, e->GetRunningCost());
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2008-06-20 07:23:00 +00:00
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_TRAIN);
|
|
|
|
if (capacity != 0) {
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(5, e->GetDefaultCargoType());
|
2008-07-26 22:00:59 +00:00
|
|
|
SetDParam(6, capacity);
|
2005-10-23 13:04:44 +00:00
|
|
|
} 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
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
const Engine *e = GetEngine(engine);
|
2009-03-13 23:49:12 +00:00
|
|
|
CargoID cargo = e->GetDefaultCargoType();
|
2009-01-25 00:57:03 +00:00
|
|
|
|
2009-03-13 23:49:12 +00:00
|
|
|
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
|
|
|
|
SetDParam(0, e->GetCost());
|
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(2, e->GetDisplayDefaultCapacity());
|
2009-03-13 23:49:12 +00:00
|
|
|
SetDParam(3, e->u.air.mail_capacity);
|
|
|
|
SetDParam(4, e->GetRunningCost());
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-03-13 23:49:12 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, e->GetCost());
|
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
|
|
|
SetDParam(2, cargo);
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(3, e->GetDisplayDefaultCapacity());
|
2009-03-13 23:49:12 +00:00
|
|
|
SetDParam(4, e->GetRunningCost());
|
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
const Engine *e = GetEngine(engine);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(2, e->GetRunningCost());
|
2009-02-21 12:52:41 +00:00
|
|
|
uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_ROAD);
|
|
|
|
if (capacity != 0) {
|
|
|
|
SetDParam(3, e->GetDefaultCargoType());
|
|
|
|
SetDParam(4, capacity);
|
|
|
|
} else {
|
|
|
|
SetDParam(3, CT_INVALID);
|
|
|
|
}
|
2005-07-01 14:05:44 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-01-25 00:57:03 +00:00
|
|
|
const Engine *e = GetEngine(engine);
|
|
|
|
|
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(2, e->GetDefaultCargoType());
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(3, e->GetDisplayDefaultCapacity());
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(4, e->GetRunningCost());
|
2005-07-01 14:05:44 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2008-03-28 08:53:36 +00:00
|
|
|
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
2007-03-03 22:03:15 +00:00
|
|
|
{
|
2008-05-13 10:17:04 +00:00
|
|
|
EngineID engine = ni->data_a;
|
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);
|
2009-02-09 02:57:15 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
|
2007-03-03 22:03:15 +00:00
|
|
|
dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-27 12:24:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Sort all items using qsort() and given 'CompareItems' function
|
|
|
|
* @param el list to be sorted
|
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
|
*/
|
2008-05-28 17:29:27 +00:00
|
|
|
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
|
2008-05-27 12:24:23 +00:00
|
|
|
{
|
2008-05-28 17:29:27 +00:00
|
|
|
uint size = el->Length();
|
2008-05-27 12:24:23 +00:00
|
|
|
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
|
|
|
|
* generally, do not sort if there are less than 2 items */
|
|
|
|
if (size < 2) return;
|
2008-05-28 17:29:27 +00:00
|
|
|
qsort(el->Begin(), size, sizeof(*el->Begin()), compare); // MorphOS doesn't know vector::at(int) ...
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
|
|
|
|
* @param el list to be sorted
|
|
|
|
* @param compare function for evaluation of the quicksort
|
|
|
|
* @param begin start of sorting
|
|
|
|
* @param num_items count of items to be sorted
|
|
|
|
*/
|
2008-05-28 17:29:27 +00:00
|
|
|
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
|
2008-05-27 12:24:23 +00:00
|
|
|
{
|
2008-05-28 20:06:00 +00:00
|
|
|
if (num_items < 2) return;
|
2008-05-28 17:29:27 +00:00
|
|
|
assert(begin < el->Length());
|
|
|
|
assert(begin + num_items <= el->Length());
|
|
|
|
qsort(el->Get(begin), num_items, sizeof(*el->Begin()), compare);
|
2008-05-27 12:24:23 +00:00
|
|
|
}
|
|
|
|
|