2006-10-10 15:02:38 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file build_vehicle_gui.cpp GUI for building vehicles. */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
#include "train.h"
|
2007-01-22 02:09:51 +00:00
|
|
|
#include "roadveh.h"
|
2007-01-22 00:26:46 +00:00
|
|
|
#include "ship.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
#include "aircraft.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2007-06-01 11:41:02 +00:00
|
|
|
#include "articulated_vehicles.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
#include "vehicle_gui.h"
|
|
|
|
#include "newgrf_engine.h"
|
2009-05-22 19:47:26 +00:00
|
|
|
#include "newgrf_text.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-01-14 16:10:58 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2008-05-17 13:01:30 +00:00
|
|
|
#include "window_gui.h"
|
2008-05-27 12:24:23 +00:00
|
|
|
#include "engine_gui.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "settings_type.h"
|
2009-06-24 21:33:11 +00:00
|
|
|
#include "cargotype.h"
|
2009-06-24 22:38:47 +00:00
|
|
|
#include "newgrf_cargo.h"
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2006-12-07 13:00:41 +00:00
|
|
|
enum BuildVehicleWidgets {
|
2006-10-10 15:02:38 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
|
|
|
|
BUILD_VEHICLE_WIDGET_CAPTION,
|
2009-04-12 17:38:01 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_LIST_CONTROL,
|
2006-10-10 15:02:38 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING,
|
|
|
|
BUILD_VEHICLE_WIDGET_SORT_DROPDOWN,
|
2009-04-12 17:38:01 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN,
|
2006-10-10 15:02:38 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_LIST,
|
|
|
|
BUILD_VEHICLE_WIDGET_SCROLLBAR,
|
|
|
|
BUILD_VEHICLE_WIDGET_PANEL,
|
|
|
|
BUILD_VEHICLE_WIDGET_BUILD,
|
|
|
|
BUILD_VEHICLE_WIDGET_RENAME,
|
|
|
|
BUILD_VEHICLE_WIDGET_RESIZE,
|
2007-03-26 11:41:14 +00:00
|
|
|
BUILD_VEHICLE_WIDGET_END
|
2006-12-07 13:00:41 +00:00
|
|
|
};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
static const Widget _build_vehicle_widgets[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW }, // BUILD_VEHICLE_WIDGET_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 239, 0, 13, 0x0, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS }, // BUILD_VEHICLE_WIDGET_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, COLOUR_GREY, 0, 239, 14, 37, 0x0, STR_NULL }, // BUILD_VEHICLE_WIDGET_LIST_CONTROL
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, // BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING
|
|
|
|
{ WWT_DROPDOWN, RESIZE_RIGHT, COLOUR_GREY, 81, 239, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, // BUILD_VEHICLE_WIDGET_SORT_DROPDOWN
|
|
|
|
{ WWT_DROPDOWN, RESIZE_RIGHT, COLOUR_GREY, 81, 239, 26, 37, 0x0, STR_FILTER_CRITERIA_TIP}, // BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, COLOUR_GREY, 0, 227, 38, 51, 0x101, STR_NULL }, // BUILD_VEHICLE_WIDGET_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 228, 239, 38, 51, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST },// BUILD_VEHICLE_WIDGET_SCROLLBAR
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 0, 239, 52, 173, 0x0, STR_NULL }, // BUILD_VEHICLE_WIDGET_PANEL
|
|
|
|
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 114, 174, 185, 0x0, STR_NULL }, // BUILD_VEHICLE_WIDGET_BUILD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 115, 227, 174, 185, 0x0, STR_NULL }, // BUILD_VEHICLE_WIDGET_RENAME
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 228, 239, 174, 185, 0x0, STR_RESIZE_BUTTON }, // BUILD_VEHICLE_WIDGET_RESIZE
|
2006-10-10 15:02:38 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2009-03-22 21:16:57 +00:00
|
|
|
static const NWidgetPart _nested_build_vehicle_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY, BUILD_VEHICLE_WIDGET_CLOSEBOX),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, BUILD_VEHICLE_WIDGET_CAPTION), SetFill(1, 0), SetResize(1, 0), SetDataTip(0x0, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
2009-04-12 17:38:01 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, BUILD_VEHICLE_WIDGET_LIST_CONTROL),
|
|
|
|
/* Sort order + criteria button row. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING), SetMinimalSize(81, 12), SetDataTip(STR_SORT_BY, STR_SORT_ORDER_TIP),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN), SetMinimalSize(159, 12), SetResize(1, 0), SetDataTip(0x0, STR_SORT_CRITERIA_TIP),
|
|
|
|
EndContainer(),
|
|
|
|
/* Filter criteria row. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetFill(1, 0),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN), SetMinimalSize(159, 12), SetResize(1, 0), SetDataTip(0x0, STR_FILTER_CRITERIA_TIP),
|
|
|
|
EndContainer(),
|
2009-03-22 21:16:57 +00:00
|
|
|
EndContainer(),
|
|
|
|
/* Vehicle list. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_MATRIX, COLOUR_GREY, BUILD_VEHICLE_WIDGET_LIST), SetMinimalSize(228, 14), SetResize(1, 1), SetDataTip(0x101, STR_NULL),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_GREY, BUILD_VEHICLE_WIDGET_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
/* Panel with details. */
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, BUILD_VEHICLE_WIDGET_PANEL), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
|
|
|
|
/* Build/rename buttons, resize button. */
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BUILD_VEHICLE_WIDGET_BUILD), SetMinimalSize(115, 12),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BUILD_VEHICLE_WIDGET_RENAME), SetMinimalSize(113, 12), SetResize(1, 0),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY, BUILD_VEHICLE_WIDGET_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
2009-03-10 21:17:00 +00:00
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
/** Special cargo filter criteria */
|
|
|
|
enum {
|
|
|
|
CF_ANY = CT_NO_REFIT, ///< Show all vehicles independent of carried cargo (i.e. no filtering)
|
|
|
|
CF_NONE = CT_INVALID, ///< Show only vehicles which do not carry cargo (e.g. train engines)
|
|
|
|
};
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
static bool _internal_sort_order; // descending/ascending
|
2007-01-22 01:13:10 +00:00
|
|
|
static byte _last_sort_criteria[] = {0, 0, 0, 0};
|
|
|
|
static bool _last_sort_order[] = {false, false, false, false};
|
2009-04-12 17:38:01 +00:00
|
|
|
static byte _last_filter_criteria[] = {0, 0, 0, 0};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
static int CDECL EngineNumberSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
2008-07-20 21:21:51 +00:00
|
|
|
int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineIntroDateSorter(const void *a, const void *b)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const int va = Engine::Get(*(const EngineID*)a)->intro_date;
|
|
|
|
const int vb = Engine::Get(*(const EngineID*)b)->intro_date;
|
2006-10-10 15:02:38 +00:00
|
|
|
const int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2006-10-10 15:02:38 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineNameSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-10-10 15:46:03 +00:00
|
|
|
static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
|
|
|
static char last_name[2][64] = { "\0", "\0" };
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
const EngineID va = *(const EngineID*)a;
|
|
|
|
const EngineID vb = *(const EngineID*)b;
|
|
|
|
|
2006-10-10 15:46:03 +00:00
|
|
|
if (va != last_engine[0]) {
|
|
|
|
last_engine[0] = va;
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, va);
|
|
|
|
GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
|
2006-10-10 15:46:03 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2006-10-10 15:46:03 +00:00
|
|
|
if (vb != last_engine[1]) {
|
|
|
|
last_engine[1] = vb;
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, vb);
|
|
|
|
GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
int r = strcmp(last_name[0], last_name[1]); // sort by name
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2006-10-10 15:46:03 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const int va = Engine::Get(*(const EngineID*)a)->reliability;
|
|
|
|
const int vb = Engine::Get(*(const EngineID*)b)->reliability;
|
2006-10-10 15:02:38 +00:00
|
|
|
const int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2006-10-10 15:02:38 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
static int CDECL EngineCostSorter(const void *a, const void *b)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
Money va = Engine::Get(*(const EngineID*)a)->GetCost();
|
|
|
|
Money vb = Engine::Get(*(const EngineID*)b)->GetCost();
|
2009-03-10 21:17:00 +00:00
|
|
|
int r = ClampToI32(va - vb);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-01-21 22:50:43 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
static int CDECL EngineSpeedSorter(const void *a, const void *b)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
int va = Engine::Get(*(const EngineID*)a)->GetDisplayMaxSpeed();
|
|
|
|
int vb = Engine::Get(*(const EngineID*)b)->GetDisplayMaxSpeed();
|
2007-01-21 22:50:43 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-01-21 22:50:43 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
static int CDECL EnginePowerSorter(const void *a, const void *b)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
int va = Engine::Get(*(const EngineID*)a)->GetPower();
|
|
|
|
int vb = Engine::Get(*(const EngineID*)b)->GetPower();
|
2007-01-21 22:50:43 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-01-21 22:50:43 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
static int CDECL EngineRunningCostSorter(const void *a, const void *b)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
Money va = Engine::Get(*(const EngineID*)a)->GetRunningCost();
|
|
|
|
Money vb = Engine::Get(*(const EngineID*)b)->GetRunningCost();
|
2007-06-21 14:32:27 +00:00
|
|
|
int r = ClampToI32(va - vb);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-01-21 22:50:43 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Train sorting functions */
|
2007-01-21 22:50:43 +00:00
|
|
|
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e_a = Engine::Get(*(const EngineID*)a);
|
|
|
|
const Engine *e_b = Engine::Get(*(const EngineID*)b);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Here we are using a few tricks to get the right sort.
|
2009-03-14 18:16:29 +00:00
|
|
|
* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
|
|
|
|
* we will actually calculate cunning cost/power (to make it more than 1).
|
|
|
|
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
|
|
|
|
* Another thing is that both power and running costs should be doubled for multiheaded engines.
|
|
|
|
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
|
2009-03-10 21:17:00 +00:00
|
|
|
Money va = (e_a->GetRunningCost()) / max(1U, (uint)e_a->GetPower());
|
|
|
|
Money vb = (e_b->GetRunningCost()) / max(1U, (uint)e_b->GetPower());
|
2007-06-21 14:32:27 +00:00
|
|
|
int r = ClampToI32(vb - va);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-01-21 22:50:43 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
2008-09-03 18:05:02 +00:00
|
|
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
|
|
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
int va = GetTotalCapacityOfArticulatedParts(*(const EngineID*)a, VEH_TRAIN) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
|
|
|
int vb = GetTotalCapacityOfArticulatedParts(*(const EngineID*)b, VEH_TRAIN) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
2007-06-02 15:41:37 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-06-02 15:41:37 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
EngineID va = *(const EngineID*)a;
|
|
|
|
EngineID vb = *(const EngineID*)b;
|
2007-01-30 17:19:58 +00:00
|
|
|
int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
|
|
|
int val_b = (RailVehInfo(vb)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
2007-01-21 22:50:43 +00:00
|
|
|
int r = val_a - val_b;
|
|
|
|
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-12-27 15:47:08 +00:00
|
|
|
/* Road vehicle sorting functions */
|
2007-06-02 15:41:37 +00:00
|
|
|
static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
2009-03-10 21:17:00 +00:00
|
|
|
int va = GetTotalCapacityOfArticulatedParts(*(const EngineID*)a, VEH_ROAD);
|
|
|
|
int vb = GetTotalCapacityOfArticulatedParts(*(const EngineID*)b, VEH_ROAD);
|
2007-12-27 15:47:08 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-12-27 15:47:08 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Ship vehicle sorting functions */
|
2007-06-02 15:41:37 +00:00
|
|
|
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e_a = Engine::Get(*(const EngineID*)a);
|
|
|
|
const Engine *e_b = Engine::Get(*(const EngineID*)b);
|
2009-03-18 19:32:13 +00:00
|
|
|
|
|
|
|
int va = e_a->GetDisplayDefaultCapacity();
|
|
|
|
int vb = e_b->GetDisplayDefaultCapacity();
|
2007-06-02 15:41:37 +00:00
|
|
|
int r = va - vb;
|
|
|
|
|
2009-03-10 21:17:00 +00:00
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
if (r == 0) return EngineNumberSorter(a, b);
|
2007-06-02 15:41:37 +00:00
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
/* Aircraft sorting functions */
|
|
|
|
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
|
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e_a = Engine::Get(*(const EngineID*)a);
|
|
|
|
const Engine *e_b = Engine::Get(*(const EngineID*)b);
|
2009-03-13 23:49:12 +00:00
|
|
|
|
2009-03-18 19:32:13 +00:00
|
|
|
int va = e_a->GetDisplayDefaultCapacity();
|
|
|
|
int vb = e_b->GetDisplayDefaultCapacity();
|
2007-06-02 15:47:38 +00:00
|
|
|
int r = va - vb;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
if (r == 0) {
|
2007-06-02 15:47:38 +00:00
|
|
|
/* The planes has the same passenger capacity. Check mail capacity instead */
|
|
|
|
va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
|
|
|
|
vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
|
|
|
|
r = va - vb;
|
|
|
|
|
|
|
|
if (r == 0) {
|
|
|
|
/* Use EngineID to sort instead since we want consistent sorting */
|
|
|
|
return EngineNumberSorter(a, b);
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
return _internal_sort_order ? -r : r;
|
|
|
|
}
|
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static EngList_SortTypeFunction * const _sorter[][10] = {{
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Trains */
|
2008-07-20 21:21:51 +00:00
|
|
|
&EngineNumberSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineCostSorter,
|
|
|
|
&EngineSpeedSorter,
|
|
|
|
&EnginePowerSorter,
|
2007-01-21 22:50:43 +00:00
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineRunningCostSorter,
|
2007-01-21 22:50:43 +00:00
|
|
|
&TrainEnginePowerVsRunningCostSorter,
|
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&TrainEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Road vehicles */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineCostSorter,
|
|
|
|
&EngineSpeedSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineRunningCostSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&RoadVehEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Ships */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineCostSorter,
|
|
|
|
&EngineSpeedSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineRunningCostSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineReliabilitySorter,
|
2007-06-02 15:41:37 +00:00
|
|
|
&ShipEngineCapacitySorter,
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Aircraft */
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineNumberSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineCostSorter,
|
|
|
|
&EngineSpeedSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineIntroDateSorter,
|
|
|
|
&EngineNameSorter,
|
2009-03-10 21:17:00 +00:00
|
|
|
&EngineRunningCostSorter,
|
2007-01-22 01:35:53 +00:00
|
|
|
&EngineReliabilitySorter,
|
|
|
|
&AircraftEngineCargoSorter,
|
|
|
|
}};
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-06-02 15:41:37 +00:00
|
|
|
static const StringID _sort_listing[][11] = {{
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Trains */
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_ENGINE_ID,
|
|
|
|
STR_SORT_BY_COST,
|
2007-01-21 22:50:43 +00:00
|
|
|
STR_SORT_BY_MAX_SPEED,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_POWER,
|
|
|
|
STR_SORT_BY_INTRO_DATE,
|
2009-07-23 19:31:50 +00:00
|
|
|
STR_SORT_BY_NAME,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_RUNNING_COST,
|
|
|
|
STR_SORT_BY_POWER_VS_RUNNING_COST,
|
2007-01-21 22:50:43 +00:00
|
|
|
STR_SORT_BY_RELIABILITY,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_CARGO_CAPACITY,
|
2007-01-21 22:50:43 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Road vehicles */
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_ENGINE_ID,
|
|
|
|
STR_SORT_BY_COST,
|
2007-12-27 15:47:08 +00:00
|
|
|
STR_SORT_BY_MAX_SPEED,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_INTRO_DATE,
|
2009-07-23 19:31:50 +00:00
|
|
|
STR_SORT_BY_NAME,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_RUNNING_COST,
|
2007-01-22 00:26:46 +00:00
|
|
|
STR_SORT_BY_RELIABILITY,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_CARGO_CAPACITY,
|
2007-01-22 00:26:46 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Ships */
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_ENGINE_ID,
|
|
|
|
STR_SORT_BY_COST,
|
2007-12-27 15:47:08 +00:00
|
|
|
STR_SORT_BY_MAX_SPEED,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_INTRO_DATE,
|
2009-07-23 19:31:50 +00:00
|
|
|
STR_SORT_BY_NAME,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_RUNNING_COST,
|
2007-01-22 01:35:53 +00:00
|
|
|
STR_SORT_BY_RELIABILITY,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_CARGO_CAPACITY,
|
2007-01-22 01:35:53 +00:00
|
|
|
INVALID_STRING_ID
|
2007-04-18 22:10:36 +00:00
|
|
|
}, {
|
2007-01-22 14:08:14 +00:00
|
|
|
/* Aircraft */
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_ENGINE_ID,
|
|
|
|
STR_SORT_BY_COST,
|
2006-10-10 15:02:38 +00:00
|
|
|
STR_SORT_BY_MAX_SPEED,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_INTRO_DATE,
|
2009-07-23 19:31:50 +00:00
|
|
|
STR_SORT_BY_NAME,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_RUNNING_COST,
|
2006-10-10 15:02:38 +00:00
|
|
|
STR_SORT_BY_RELIABILITY,
|
2009-07-22 22:44:56 +00:00
|
|
|
STR_SORT_BY_CARGO_CAPACITY,
|
2006-10-10 15:02:38 +00:00
|
|
|
INVALID_STRING_ID
|
2007-01-22 01:35:53 +00:00
|
|
|
}};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
/** Cargo filter functions */
|
2009-04-12 18:40:39 +00:00
|
|
|
static bool CDECL CargoFilter(const EngineID *eid, const CargoID cid)
|
2009-04-12 17:38:01 +00:00
|
|
|
{
|
|
|
|
if (cid == CF_ANY) return true;
|
2009-05-16 23:34:14 +00:00
|
|
|
uint32 refit_mask = GetUnionOfArticulatedRefitMasks(*eid, Engine::Get(*eid)->type, true);
|
2009-04-12 17:38:01 +00:00
|
|
|
return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GUIEngineList::FilterFunction * const _filter_funcs[] = {
|
|
|
|
&CargoFilter,
|
|
|
|
};
|
|
|
|
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, VehicleType type, bool refittable)
|
2008-02-14 07:25:24 +00:00
|
|
|
{
|
2009-06-27 21:36:04 +00:00
|
|
|
CargoArray cap = GetCapacityOfArticulatedParts(engine, type);
|
2008-02-14 07:25:24 +00:00
|
|
|
|
2009-06-27 21:36:04 +00:00
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
2008-02-14 07:25:24 +00:00
|
|
|
if (cap[c] == 0) continue;
|
|
|
|
|
|
|
|
SetDParam(0, c);
|
|
|
|
SetDParam(1, cap[c]);
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(2, refittable ? STR_REFITTABLE : STR_EMPTY);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-02-14 07:25:24 +00:00
|
|
|
|
|
|
|
/* Only show as refittable once */
|
|
|
|
refittable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Draw rail wagon specific details */
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2009-01-25 00:57:03 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Purchase cost */
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Wagon weight - (including cargo) */
|
2009-02-01 16:10:06 +00:00
|
|
|
uint weight = e->GetDisplayWeight();
|
2007-05-07 16:38:21 +00:00
|
|
|
SetDParam(0, weight);
|
2009-07-16 19:00:13 +00:00
|
|
|
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * e->GetDisplayDefaultCapacity() >> 4 : 0);
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(1, cargo_weight + weight);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Wagon speed limit, displayed if above zero */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.vehicle.wagon_speed_limits) {
|
2009-02-01 16:10:06 +00:00
|
|
|
uint max_speed = e->GetDisplayMaxSpeed();
|
2007-05-07 16:38:21 +00:00
|
|
|
if (max_speed > 0) {
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(0, max_speed);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-05-07 16:38:21 +00:00
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2008-02-21 19:09:10 +00:00
|
|
|
|
|
|
|
/* Running cost */
|
|
|
|
if (rvi->running_cost_class != 0xFF) {
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetRunningCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-02-21 19:09:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw locomotive specific details */
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Purchase Cost - Engine weight */
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetCost());
|
2009-02-19 09:45:44 +00:00
|
|
|
SetDParam(1, e->GetDisplayWeight());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Max speed - Engine power */
|
2009-02-01 16:10:06 +00:00
|
|
|
SetDParam(0, e->GetDisplayMaxSpeed());
|
|
|
|
SetDParam(1, e->GetPower());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Max tractive effort - not applicable if old acceleration or maglev */
|
2009-01-23 20:53:43 +00:00
|
|
|
if (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && rvi->railtype != RAILTYPE_MAGLEV) {
|
2009-02-19 09:45:44 +00:00
|
|
|
SetDParam(0, e->GetDisplayMaxTractiveEffort());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Running cost */
|
2008-02-21 19:09:10 +00:00
|
|
|
if (rvi->running_cost_class != 0xFF) {
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetRunningCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-02-21 19:09:10 +00:00
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Powered wagons power - Powered wagons extra weight */
|
|
|
|
if (rvi->pow_wag_power != 0) {
|
|
|
|
SetDParam(0, rvi->pow_wag_power);
|
|
|
|
SetDParam(1, rvi->pow_wag_weight);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-22 02:09:51 +00:00
|
|
|
/* Draw road vehicle specific details */
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number)
|
2007-01-22 02:09:51 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2009-01-25 00:57:03 +00:00
|
|
|
|
2007-01-22 02:09:51 +00:00
|
|
|
/* Purchase cost - Max speed */
|
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-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-22 02:09:51 +00:00
|
|
|
|
|
|
|
/* Running cost */
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetRunningCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-22 02:09:51 +00:00
|
|
|
|
2009-02-27 20:40:39 +00:00
|
|
|
return y;
|
2007-01-22 02:09:51 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 00:26:46 +00:00
|
|
|
/* Draw ship specific details */
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, const ShipVehicleInfo *svi, bool refittable)
|
2007-01-22 00:26:46 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2009-01-25 00:57:03 +00:00
|
|
|
|
2007-01-22 00:26:46 +00:00
|
|
|
/* Purchase cost - Max speed */
|
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-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-22 00:26:46 +00:00
|
|
|
|
|
|
|
/* Cargo type + capacity */
|
2009-02-21 12:52:41 +00:00
|
|
|
SetDParam(0, e->GetDefaultCargoType());
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(1, e->GetDisplayDefaultCapacity());
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(2, refittable ? STR_REFITTABLE : STR_EMPTY);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-22 00:26:46 +00:00
|
|
|
|
|
|
|
/* Running cost */
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetRunningCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-22 00:26:46 +00:00
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Draw aircraft specific details */
|
2009-03-22 11:06:25 +00:00
|
|
|
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, const AircraftVehicleInfo *avi, bool refittable)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2009-02-21 12:52:41 +00:00
|
|
|
CargoID cargo = e->GetDefaultCargoType();
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
/* Purchase cost - Max speed */
|
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-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
/* Cargo capacity */
|
|
|
|
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
|
2009-04-21 16:52:58 +00:00
|
|
|
SetDParam(0, CT_PASSENGERS);
|
|
|
|
SetDParam(1, e->GetDisplayDefaultCapacity());
|
|
|
|
SetDParam(2, CT_MAIL);
|
|
|
|
SetDParam(3, avi->mail_capacity);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
|
2006-10-10 15:02:38 +00:00
|
|
|
} else {
|
|
|
|
/* Note, if the default capacity is selected by the refit capacity
|
2009-03-14 18:16:29 +00:00
|
|
|
* callback, then the capacity shown is likely to be incorrect. */
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, cargo);
|
2009-03-18 19:32:13 +00:00
|
|
|
SetDParam(1, e->GetDisplayDefaultCapacity());
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(2, refittable ? STR_REFITTABLE : STR_EMPTY);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
/* Running cost */
|
2009-01-25 00:57:03 +00:00
|
|
|
SetDParam(0, e->GetRunningCost());
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
return y;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-05-22 19:47:26 +00:00
|
|
|
/**
|
|
|
|
* Display additional text from NewGRF in the purchase information window
|
|
|
|
* @param left Left border of text bounding box
|
|
|
|
* @param right Right border of text bounding box
|
|
|
|
* @param y Top border of text bounding box
|
|
|
|
* @param engine Engine to query the additional purchase information for
|
|
|
|
* @return Bottom border of text bounding box
|
|
|
|
*/
|
|
|
|
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
|
|
|
|
{
|
|
|
|
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
|
|
|
|
if (callback == CALLBACK_FAILED) return y;
|
|
|
|
|
|
|
|
/* STR_BLACK_STRING is used to start the string with {BLACK} */
|
|
|
|
SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback));
|
|
|
|
PrepareTextRefStackUsage(0);
|
|
|
|
uint result = DrawStringMultiLine(left, right, y, INT32_MAX, STR_BLACK_STRING);
|
|
|
|
StopTextRefStackUsage();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-01-21 22:50:43 +00:00
|
|
|
/**
|
|
|
|
* Draw the purchase info details of a vehicle at a given location.
|
2009-03-22 11:06:25 +00:00
|
|
|
* @param left,right,y location where to draw the info
|
2007-01-21 22:50:43 +00:00
|
|
|
* @param engine_number the engine of which to draw the info of
|
2007-03-26 11:41:14 +00:00
|
|
|
* @return y after drawing all the text
|
2007-01-21 22:50:43 +00:00
|
|
|
*/
|
2009-03-22 11:06:25 +00:00
|
|
|
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
|
2007-01-21 22:50:43 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
const Engine *e = Engine::Get(engine_number);
|
2007-01-21 22:50:43 +00:00
|
|
|
YearMonthDay ymd;
|
|
|
|
ConvertDateToYMD(e->intro_date, &ymd);
|
2009-02-27 20:40:39 +00:00
|
|
|
bool refittable = IsArticulatedVehicleRefittable(engine_number);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
switch (e->type) {
|
2007-05-18 17:31:41 +00:00
|
|
|
default: NOT_REACHED();
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: {
|
2007-01-21 22:50:43 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
2007-01-30 11:53:35 +00:00
|
|
|
if (rvi->railveh_type == RAILVEH_WAGON) {
|
2009-03-22 11:06:25 +00:00
|
|
|
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, rvi);
|
2007-01-21 22:50:43 +00:00
|
|
|
} else {
|
2009-03-22 11:06:25 +00:00
|
|
|
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, rvi);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cargo type + capacity, or N/A */
|
2009-03-22 11:06:25 +00:00
|
|
|
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, VEH_TRAIN, refittable);
|
2008-02-14 07:25:24 +00:00
|
|
|
|
|
|
|
if (new_y == y) {
|
2007-01-21 22:50:43 +00:00
|
|
|
SetDParam(0, CT_INVALID);
|
|
|
|
SetDParam(2, STR_EMPTY);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
} else {
|
2008-02-14 07:25:24 +00:00
|
|
|
y = new_y;
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-02-14 07:25:24 +00:00
|
|
|
}
|
2009-02-27 20:40:39 +00:00
|
|
|
case VEH_ROAD: {
|
2009-03-22 11:06:25 +00:00
|
|
|
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number);
|
2009-02-27 20:40:39 +00:00
|
|
|
|
|
|
|
/* Cargo type + capacity, or N/A */
|
2009-03-22 11:06:25 +00:00
|
|
|
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, VEH_ROAD, refittable);
|
2009-02-27 20:40:39 +00:00
|
|
|
|
|
|
|
if (new_y == y) {
|
|
|
|
SetDParam(0, CT_INVALID);
|
|
|
|
SetDParam(2, STR_EMPTY);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2009-02-27 20:40:39 +00:00
|
|
|
} else {
|
|
|
|
y = new_y;
|
|
|
|
}
|
2007-01-22 02:09:51 +00:00
|
|
|
break;
|
2009-02-27 20:40:39 +00:00
|
|
|
}
|
2008-12-16 22:02:12 +00:00
|
|
|
case VEH_SHIP:
|
2009-03-22 11:06:25 +00:00
|
|
|
y = DrawShipPurchaseInfo(left, right, y, engine_number, ShipVehInfo(engine_number), refittable);
|
2008-12-16 22:02:12 +00:00
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2009-03-22 11:06:25 +00:00
|
|
|
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, AircraftVehInfo(engine_number), refittable);
|
2007-01-21 22:50:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw details, that applies to all types except rail wagons */
|
2007-03-08 16:27:54 +00:00
|
|
|
if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
|
2007-01-21 22:50:43 +00:00
|
|
|
/* Design date - Life length */
|
|
|
|
SetDParam(0, ymd.year);
|
2009-06-16 13:52:18 +00:00
|
|
|
SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
|
|
|
|
/* Reliability */
|
|
|
|
SetDParam(0, e->reliability * 100 >> 16);
|
2009-04-26 14:52:56 +00:00
|
|
|
DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
|
2009-03-25 20:16:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
|
|
|
/* Additional text from NewGRF */
|
2009-03-22 11:06:25 +00:00
|
|
|
y = ShowAdditionalText(left, right, y, engine_number);
|
|
|
|
if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
|
2007-03-26 11:41:14 +00:00
|
|
|
|
|
|
|
return y;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2008-02-04 11:28:12 +00:00
|
|
|
static void DrawVehicleEngine(VehicleType type, int x, int y, EngineID engine, SpriteID pal)
|
2007-01-22 23:23:30 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN: DrawTrainEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_ROAD: DrawRoadVehEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_SHIP: DrawShipEngine( x, y, engine, pal); break;
|
|
|
|
case VEH_AIRCRAFT: DrawAircraftEngine(x, y, engine, pal); break;
|
2007-01-22 23:23:30 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Engine drawing loop
|
|
|
|
* @param type Type of vehicle (VEH_*)
|
|
|
|
* @param x,y Where should the list start
|
|
|
|
* @param eng_list What engines to draw
|
|
|
|
* @param min where to start in the list
|
2007-01-23 01:00:56 +00:00
|
|
|
* @param max where in the list to end
|
2007-01-22 23:23:30 +00:00
|
|
|
* @param selected_id what engine to highlight as selected, if any
|
2008-04-22 23:16:36 +00:00
|
|
|
* @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off
|
2007-01-22 23:23:30 +00:00
|
|
|
*/
|
2008-07-22 16:13:42 +00:00
|
|
|
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
|
2007-01-22 23:23:30 +00:00
|
|
|
{
|
|
|
|
byte step_size = GetVehicleListHeight(type);
|
|
|
|
byte x_offset = 0;
|
|
|
|
byte y_offset = 0;
|
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
assert(max <= eng_list->Length());
|
2007-01-23 01:00:56 +00:00
|
|
|
|
2007-01-22 23:23:30 +00:00
|
|
|
switch (type) {
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_TRAIN:
|
2007-01-22 23:23:30 +00:00
|
|
|
x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
|
|
|
|
/* Fallthough */
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_ROAD:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 26;
|
|
|
|
x_offset = 30;
|
|
|
|
y += 2;
|
|
|
|
y_offset = 4;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_SHIP:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 35;
|
|
|
|
x_offset = 40;
|
|
|
|
y += 7;
|
|
|
|
y_offset = 3;
|
|
|
|
break;
|
2007-03-08 16:27:54 +00:00
|
|
|
case VEH_AIRCRAFT:
|
2007-01-22 23:23:30 +00:00
|
|
|
x += 27;
|
|
|
|
x_offset = 33;
|
|
|
|
y += 7;
|
|
|
|
y_offset = 3;
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; min < max; min++, y += step_size) {
|
2008-05-28 10:29:48 +00:00
|
|
|
const EngineID engine = (*eng_list)[min];
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
|
|
|
|
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
|
2007-01-22 23:23:30 +00:00
|
|
|
|
2007-06-25 14:46:32 +00:00
|
|
|
SetDParam(0, engine);
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(x + x_offset, r, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
|
2008-09-30 20:39:50 +00:00
|
|
|
DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
|
2008-04-22 23:16:36 +00:00
|
|
|
if (count_location != 0) {
|
2007-05-19 09:40:18 +00:00
|
|
|
SetDParam(0, num_engines);
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(x, count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT);
|
2007-02-06 11:11:12 +00:00
|
|
|
}
|
2007-01-22 23:23:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
struct BuildVehicleWindow : Window {
|
|
|
|
VehicleType vehicle_type;
|
|
|
|
union {
|
|
|
|
RailTypeByte railtype;
|
|
|
|
AirportFTAClass::Flags flags;
|
|
|
|
RoadTypes roadtypes;
|
|
|
|
} filter;
|
|
|
|
bool descending_sort_order;
|
|
|
|
byte sort_criteria;
|
2008-07-13 02:43:46 +00:00
|
|
|
bool listview_mode;
|
2008-05-13 14:28:27 +00:00
|
|
|
EngineID sel_engine;
|
|
|
|
EngineID rename_engine;
|
2008-05-28 17:29:27 +00:00
|
|
|
GUIEngineList eng_list;
|
2009-04-12 17:38:01 +00:00
|
|
|
CargoID cargo_filter[NUM_CARGO + 2]; ///< Available cargo filters; CargoID or CF_ANY or CF_NONE
|
|
|
|
StringID cargo_filter_texts[NUM_CARGO + 3]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
|
|
|
|
byte cargo_filter_criteria; ///< Selected cargo filter
|
2008-05-13 14:28:27 +00:00
|
|
|
|
2009-01-03 16:06:58 +00:00
|
|
|
BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == INVALID_TILE ? (int)type : tile)
|
2008-05-13 14:28:27 +00:00
|
|
|
{
|
|
|
|
this->vehicle_type = type;
|
|
|
|
int vlh = GetVehicleListHeight(this->vehicle_type);
|
|
|
|
|
|
|
|
ResizeWindow(this, 0, vlh - 14);
|
|
|
|
this->resize.step_height = vlh;
|
|
|
|
this->vscroll.cap = 1;
|
2009-07-16 16:22:23 +00:00
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (1 << MAT_ROW_START) | (1 << MAT_COL_START);
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
this->resize.width = this->width;
|
|
|
|
this->resize.height = this->height;
|
|
|
|
|
2009-02-09 02:33:10 +00:00
|
|
|
this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
this->sel_engine = INVALID_ENGINE;
|
|
|
|
|
|
|
|
this->sort_criteria = _last_sort_criteria[type];
|
|
|
|
this->descending_sort_order = _last_sort_order[type];
|
2009-04-12 17:38:01 +00:00
|
|
|
this->cargo_filter_criteria = _last_filter_criteria[type];
|
|
|
|
|
|
|
|
/* Populate filter list */
|
|
|
|
uint filter_items = 0;
|
|
|
|
|
|
|
|
/* Add item for disabling filtering */
|
|
|
|
this->cargo_filter[filter_items] = CF_ANY;
|
|
|
|
this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
|
|
|
|
filter_items++;
|
|
|
|
|
|
|
|
/* Add item for vehicles not carrying anything, e.g. train engines.
|
|
|
|
* This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
|
|
|
|
if (type == VEH_TRAIN) {
|
|
|
|
this->cargo_filter[filter_items] = CF_NONE;
|
2009-04-21 23:40:56 +00:00
|
|
|
this->cargo_filter_texts[filter_items] = STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE;
|
2009-04-12 17:38:01 +00:00
|
|
|
filter_items++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Collect available cargo types for filtering */
|
2009-07-16 20:40:06 +00:00
|
|
|
const CargoSpec *cargo;
|
|
|
|
FOR_ALL_CARGOSPECS(cargo) {
|
|
|
|
if (IsCargoInClass(cargo->Index(), CC_SPECIAL)) continue; // exclude fake cargo types
|
|
|
|
this->cargo_filter[filter_items] = cargo->Index();
|
2009-04-12 17:38:01 +00:00
|
|
|
this->cargo_filter_texts[filter_items] = cargo->name;
|
|
|
|
filter_items++;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
|
|
|
|
if (this->cargo_filter_criteria >= filter_items) this->cargo_filter_criteria = 0;
|
|
|
|
|
|
|
|
this->eng_list.SetFilterFuncs(_filter_funcs);
|
|
|
|
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN:
|
2009-01-03 16:06:58 +00:00
|
|
|
this->filter.railtype = (tile == INVALID_TILE) ? RAILTYPE_END : GetRailType(tile);
|
2008-05-13 14:28:27 +00:00
|
|
|
break;
|
|
|
|
case VEH_ROAD:
|
2009-01-03 16:06:58 +00:00
|
|
|
this->filter.roadtypes = (tile == INVALID_TILE) ? ROADTYPES_ALL : GetRoadTypes(tile);
|
2008-05-13 14:28:27 +00:00
|
|
|
case VEH_SHIP:
|
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
this->filter.flags =
|
2009-06-24 17:39:54 +00:00
|
|
|
tile == INVALID_TILE ? AirportFTAClass::ALL : Station::GetByTile(tile)->Airport()->flags;
|
2008-05-13 14:28:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->SetupWindowStrings(type);
|
2008-07-13 02:43:46 +00:00
|
|
|
|
|
|
|
this->listview_mode = (this->window_number <= VEH_END);
|
|
|
|
/* If we are just viewing the list of vehicles, we do not need the Build button.
|
|
|
|
* So we just hide it, and enlarge the Rename buton by the now vacant place. */
|
|
|
|
if (this->listview_mode) {
|
|
|
|
this->HideWidget(BUILD_VEHICLE_WIDGET_BUILD);
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_RENAME].left = this->widget[BUILD_VEHICLE_WIDGET_BUILD].left;
|
|
|
|
} else {
|
|
|
|
/* Both are visible, adjust the size of each */
|
|
|
|
ResizeButtons(this, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
|
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
|
2009-04-12 14:12:17 +00:00
|
|
|
this->eng_list.ForceRebuild();
|
2008-05-13 14:28:27 +00:00
|
|
|
this->GenerateBuildList(); // generate the list, since we need it in the next line
|
|
|
|
/* Select the first engine in the list as default when opening the window */
|
2008-05-28 17:29:27 +00:00
|
|
|
if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup widget strings to fit the different types of vehicles */
|
|
|
|
void SetupWindowStrings(VehicleType type)
|
|
|
|
{
|
2009-07-22 20:17:07 +00:00
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = (this->listview_mode ? STR_AVAILABLE_TRAINS : STR_BUILD_VEHICLE_TRAIN_ALL_CAPTION) + type;
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips = STR_BUILD_VEHICLE_TRAIN_LIST_TOOLTIP + type;
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_BUILD].data = STR_BUILD_VEHICLE_TRAIN_BUILD_VEHICLE_BUTTON + type;
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips = STR_BUILD_VEHICLE_TRAIN_BUILD_VEHICLE_TOOLTIP + type;
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_RENAME].data = STR_BUILD_VEHICLE_TRAIN_RENAME_BUTTON + type;
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_BUILD_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
|
|
|
|
|
|
|
|
if (type == VEH_TRAIN && this->listview_mode) this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data = STR_JUST_STRING;
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
/** Filter the engine list against the currently selected cargo filter */
|
|
|
|
void FilterEngineList()
|
|
|
|
{
|
|
|
|
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
|
|
|
|
if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine
|
|
|
|
this->sel_engine = INVALID_ENGINE;
|
|
|
|
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
|
|
|
|
this->sel_engine = this->eng_list[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Filter a single engine */
|
|
|
|
bool FilterSingleEngine(EngineID eid)
|
|
|
|
{
|
|
|
|
CargoID filter_type = this->cargo_filter[this->cargo_filter_criteria];
|
|
|
|
return (filter_type == CF_ANY || CargoFilter(&eid, filter_type));
|
|
|
|
}
|
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Figure out what train EngineIDs to put in the list */
|
|
|
|
void GenerateBuildTrainList()
|
|
|
|
{
|
|
|
|
EngineID sel_id = INVALID_ENGINE;
|
|
|
|
int num_engines = 0;
|
|
|
|
int num_wagons = 0;
|
2008-01-17 18:49:39 +00:00
|
|
|
|
2008-07-13 02:43:46 +00:00
|
|
|
this->filter.railtype = (this->listview_mode) ? RAILTYPE_END : GetRailType(this->window_number);
|
2008-01-17 18:49:39 +00:00
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
this->eng_list.Clear();
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Make list of all available train engines and wagons.
|
2009-03-14 18:16:29 +00:00
|
|
|
* Also check to see if the previously selected engine is still available,
|
|
|
|
* and if not, reset selection to INVALID_ENGINE. This could be the case
|
|
|
|
* when engines become obsolete and are removed */
|
2008-05-13 14:28:27 +00:00
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
|
|
|
|
EngineID eid = e->index;
|
|
|
|
const RailVehicleInfo *rvi = &e->u.rail;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
if (this->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
|
2007-03-26 11:41:14 +00:00
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
/* Filter now! So num_engines and num_wagons is valid */
|
|
|
|
if (!FilterSingleEngine(eid)) continue;
|
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
*this->eng_list.Append() = eid;
|
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
if (rvi->railveh_type != RAILVEH_WAGON) {
|
|
|
|
num_engines++;
|
|
|
|
} else {
|
|
|
|
num_wagons++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eid == this->sel_engine) sel_id = eid;
|
2008-01-26 20:55:04 +00:00
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
this->sel_engine = sel_id;
|
|
|
|
|
|
|
|
/* make engines first, and then wagons, sorted by ListPositionOfEngine() */
|
|
|
|
_internal_sort_order = false;
|
|
|
|
EngList_Sort(&this->eng_list, TrainEnginesThenWagonsSorter);
|
|
|
|
|
|
|
|
/* and then sort engines */
|
|
|
|
_internal_sort_order = this->descending_sort_order;
|
|
|
|
EngList_SortPartial(&this->eng_list, _sorter[0][this->sort_criteria], 0, num_engines);
|
|
|
|
|
|
|
|
/* and finally sort wagons */
|
|
|
|
EngList_SortPartial(&this->eng_list, _sorter[0][this->sort_criteria], num_engines, num_wagons);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2007-01-22 23:23:30 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Figure out what road vehicle EngineIDs to put in the list */
|
|
|
|
void GenerateBuildRoadVehList()
|
|
|
|
{
|
|
|
|
EngineID sel_id = INVALID_ENGINE;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
this->eng_list.Clear();
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
|
|
|
|
EngineID eid = e->index;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
|
2008-05-13 14:28:27 +00:00
|
|
|
if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
|
2008-05-28 17:29:27 +00:00
|
|
|
*this->eng_list.Append() = eid;
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
if (eid == this->sel_engine) sel_id = eid;
|
2006-11-30 16:03:12 +00:00
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
this->sel_engine = sel_id;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Figure out what ship EngineIDs to put in the list */
|
|
|
|
void GenerateBuildShipList()
|
|
|
|
{
|
|
|
|
EngineID sel_id = INVALID_ENGINE;
|
2008-05-28 17:29:27 +00:00
|
|
|
this->eng_list.Clear();
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
|
|
|
|
EngineID eid = e->index;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
|
2008-05-28 17:29:27 +00:00
|
|
|
*this->eng_list.Append() = eid;
|
2008-05-13 14:28:27 +00:00
|
|
|
|
|
|
|
if (eid == this->sel_engine) sel_id = eid;
|
|
|
|
}
|
|
|
|
this->sel_engine = sel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out what aircraft EngineIDs to put in the list */
|
|
|
|
void GenerateBuildAircraftList()
|
|
|
|
{
|
|
|
|
EngineID sel_id = INVALID_ENGINE;
|
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
this->eng_list.Clear();
|
2008-05-13 14:28:27 +00:00
|
|
|
|
2009-06-24 17:39:54 +00:00
|
|
|
const Station *st = this->listview_mode ? NULL : Station::GetByTile(this->window_number);
|
2009-01-10 09:51:14 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Make list of all available planes.
|
2009-03-14 18:16:29 +00:00
|
|
|
* Also check to see if the previously selected plane is still available,
|
|
|
|
* and if not, reset selection to INVALID_ENGINE. This could be the case
|
|
|
|
* when planes become obsolete and are removed */
|
2008-05-13 14:28:27 +00:00
|
|
|
const Engine *e;
|
|
|
|
FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) {
|
|
|
|
EngineID eid = e->index;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
|
2008-05-13 14:28:27 +00:00
|
|
|
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
|
2009-01-10 09:51:14 +00:00
|
|
|
if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
|
2008-05-13 14:28:27 +00:00
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
*this->eng_list.Append() = eid;
|
2008-05-13 14:28:27 +00:00
|
|
|
if (eid == this->sel_engine) sel_id = eid;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->sel_engine = sel_id;
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Generate the list of vehicles */
|
|
|
|
void GenerateBuildList()
|
|
|
|
{
|
2009-04-12 14:12:17 +00:00
|
|
|
if (!this->eng_list.NeedRebuild()) return;
|
2008-05-13 14:28:27 +00:00
|
|
|
switch (this->vehicle_type) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case VEH_TRAIN:
|
|
|
|
this->GenerateBuildTrainList();
|
2009-04-12 14:12:17 +00:00
|
|
|
this->eng_list.Compact();
|
|
|
|
this->eng_list.RebuildDone();
|
2008-05-13 14:28:27 +00:00
|
|
|
return; // trains should not reach the last sorting
|
|
|
|
case VEH_ROAD:
|
|
|
|
this->GenerateBuildRoadVehList();
|
|
|
|
break;
|
|
|
|
case VEH_SHIP:
|
|
|
|
this->GenerateBuildShipList();
|
|
|
|
break;
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
this->GenerateBuildAircraftList();
|
|
|
|
break;
|
|
|
|
}
|
2009-04-12 17:38:01 +00:00
|
|
|
|
|
|
|
this->FilterEngineList();
|
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
_internal_sort_order = this->descending_sort_order;
|
|
|
|
EngList_Sort(&this->eng_list, _sorter[this->vehicle_type][this->sort_criteria]);
|
2009-04-12 14:12:17 +00:00
|
|
|
|
|
|
|
this->eng_list.Compact();
|
|
|
|
this->eng_list.RebuildDone();
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
|
|
|
|
this->descending_sort_order ^= true;
|
|
|
|
_last_sort_order[this->vehicle_type] = this->descending_sort_order;
|
2009-04-12 14:12:17 +00:00
|
|
|
this->eng_list.ForceRebuild();
|
2008-05-13 14:28:27 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_LIST: {
|
|
|
|
uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.pos;
|
2008-05-28 17:29:27 +00:00
|
|
|
size_t num_items = this->eng_list.Length();
|
2008-05-13 14:28:27 +00:00
|
|
|
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
|
|
|
|
ShowDropDownMenu(this, _sort_listing[this->vehicle_type], this->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
|
|
|
|
break;
|
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
case BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
|
|
|
|
ShowDropDownMenu(this, this->cargo_filter_texts, this->cargo_filter_criteria, BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN, 0, 0);
|
|
|
|
break;
|
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
case BUILD_VEHICLE_WIDGET_BUILD: {
|
|
|
|
EngineID sel_eng = this->sel_engine;
|
|
|
|
if (sel_eng != INVALID_ENGINE) {
|
2009-07-22 23:39:35 +00:00
|
|
|
CommandCallback *callback;
|
2008-05-13 14:28:27 +00:00
|
|
|
switch (this->vehicle_type) {
|
|
|
|
default: NOT_REACHED();
|
2009-07-22 23:39:35 +00:00
|
|
|
case VEH_TRAIN: callback = (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco; break;
|
|
|
|
case VEH_ROAD: callback = CcBuildRoadVeh; break;
|
|
|
|
case VEH_SHIP: callback = CcBuildShip; break;
|
|
|
|
case VEH_AIRCRAFT: callback = CcBuildAircraft; break;
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
2009-07-22 23:39:35 +00:00
|
|
|
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
break;
|
2006-11-30 18:47:57 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
case BUILD_VEHICLE_WIDGET_RENAME: {
|
|
|
|
EngineID sel_eng = this->sel_engine;
|
|
|
|
if (sel_eng != INVALID_ENGINE) {
|
|
|
|
this->rename_engine = sel_eng;
|
|
|
|
SetDParam(0, sel_eng);
|
2009-07-22 20:17:07 +00:00
|
|
|
ShowQueryString(STR_ENGINE_NAME, STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
|
2007-01-21 22:50:43 +00:00
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
break;
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
2009-04-12 14:12:17 +00:00
|
|
|
this->eng_list.ForceRebuild();
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-04-12 14:12:17 +00:00
|
|
|
this->GenerateBuildList();
|
2007-07-29 22:58:59 +00:00
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.Length());
|
2007-07-29 22:58:59 +00:00
|
|
|
|
2008-05-28 17:29:27 +00:00
|
|
|
SetVScrollCount(this, this->eng_list.Length());
|
2008-08-24 21:31:24 +00:00
|
|
|
if (this->vehicle_type == VEH_TRAIN) {
|
|
|
|
if (this->filter.railtype == RAILTYPE_END) {
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(0, STR_BUILD_VEHICLE_TRAIN_ALL_CAPTION);
|
2008-08-24 21:31:24 +00:00
|
|
|
} else {
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
|
|
|
|
SetDParam(0, rti->strings.build_caption);
|
|
|
|
}
|
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
/* Set text of sort by dropdown */
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria];
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-04-12 17:38:01 +00:00
|
|
|
/* Set text of 'cargo filter by' dropdown */
|
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN].data = this->cargo_filter_texts[this->cargo_filter_criteria];
|
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-07-22 16:13:42 +00:00
|
|
|
DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].right, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
if (this->sel_engine != INVALID_ENGINE) {
|
|
|
|
const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];
|
2009-03-22 11:06:25 +00:00
|
|
|
int text_end = DrawVehiclePurchaseInfo(wi->left + 2, wi->right - 2, wi->top + 1, this->sel_engine);
|
2007-06-22 10:57:53 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
if (text_end > wi->bottom) {
|
|
|
|
this->SetDirty();
|
|
|
|
ResizeWindowForWidget(this, BUILD_VEHICLE_WIDGET_PANEL, 0, text_end - wi->bottom);
|
|
|
|
this->SetDirty();
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2006-11-30 16:03:12 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawSortButtonState(BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDoubleClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget == BUILD_VEHICLE_WIDGET_LIST) {
|
|
|
|
/* When double clicking, we want to buy a vehicle */
|
|
|
|
this->OnClick(pt, BUILD_VEHICLE_WIDGET_BUILD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
2008-09-15 19:02:50 +00:00
|
|
|
if (str == NULL) return;
|
|
|
|
|
2009-07-22 20:17:07 +00:00
|
|
|
DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type), NULL, str);
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
2009-04-12 17:38:01 +00:00
|
|
|
switch (widget) {
|
|
|
|
case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN:
|
|
|
|
if (this->sort_criteria != index) {
|
|
|
|
this->sort_criteria = index;
|
|
|
|
_last_sort_criteria[this->vehicle_type] = this->sort_criteria;
|
|
|
|
this->eng_list.ForceRebuild();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUILD_VEHICLE_WIDGET_CARGO_FILTER_DROPDOWN: // Select a cargo filter criteria
|
|
|
|
if (this->cargo_filter_criteria != index) {
|
|
|
|
this->cargo_filter_criteria = index;
|
|
|
|
_last_filter_criteria[this->vehicle_type] = this->cargo_filter_criteria;
|
|
|
|
/* deactivate filter if criteria is 'Show All', activate it otherwise */
|
|
|
|
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
|
|
|
|
this->eng_list.ForceRebuild();
|
|
|
|
}
|
|
|
|
break;
|
2008-05-13 14:28:27 +00:00
|
|
|
}
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2009-03-29 09:49:11 +00:00
|
|
|
virtual void OnResize(Point delta)
|
2008-05-13 14:28:27 +00:00
|
|
|
{
|
2008-07-13 02:43:46 +00:00
|
|
|
if (delta.x != 0 && !this->listview_mode) {
|
|
|
|
ResizeButtons(this, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
|
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
if (delta.y == 0) return;
|
|
|
|
|
|
|
|
this->vscroll.cap += delta.y / (int)GetVehicleListHeight(this->vehicle_type);
|
2009-07-16 16:22:23 +00:00
|
|
|
this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|
2008-05-13 14:28:27 +00:00
|
|
|
};
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _build_vehicle_desc(
|
2009-04-12 17:38:01 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 240, 186, 240, 268,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_BUILD_VEHICLE, WC_NONE,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE | WDF_CONSTRUCTION,
|
2009-03-22 21:16:57 +00:00
|
|
|
_build_vehicle_widgets, _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2007-05-18 17:31:41 +00:00
|
|
|
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
|
2006-10-10 15:02:38 +00:00
|
|
|
{
|
2007-07-13 14:51:55 +00:00
|
|
|
/* We want to be able to open both Available Train as Available Ships,
|
2009-01-03 16:06:58 +00:00
|
|
|
* so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
|
2007-07-13 14:51:55 +00:00
|
|
|
* As it always is a low value, it won't collide with any real tile
|
|
|
|
* number. */
|
2009-01-03 16:06:58 +00:00
|
|
|
uint num = (tile == INVALID_TILE) ? (int)type : tile;
|
2006-10-10 15:02:38 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
assert(IsCompanyBuildableVehicleType(type));
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2007-07-13 14:51:55 +00:00
|
|
|
DeleteWindowById(WC_BUILD_VEHICLE, num);
|
2007-01-21 22:50:43 +00:00
|
|
|
|
2008-05-13 14:28:27 +00:00
|
|
|
new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
|
2006-10-10 15:02:38 +00:00
|
|
|
}
|