src/build_vehicle_gui.cpp
author bjarni
Mon, 22 Jan 2007 14:08:14 +0000
changeset 5790 d4a732968bda
parent 5787 49f49e4b3e3e
child 5800 672266389034
permissions -rw-r--r--
(svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     1
/* $Id$ */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     2
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     3
#include "stdafx.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     4
#include "openttd.h"
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
     5
#include "train.h"
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
     6
#include "roadveh.h"
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
     7
#include "ship.h"
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     8
#include "aircraft.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     9
#include "debug.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    10
#include "functions.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    11
#include "table/sprites.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    12
#include "table/strings.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    13
#include "window.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    14
#include "gui.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    15
#include "vehicle.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    16
#include "gfx.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    17
#include "station.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    18
#include "command.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    19
#include "engine.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    20
#include "player.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    21
#include "depot.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    22
#include "airport.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    23
#include "vehicle_gui.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    24
#include "newgrf_engine.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    25
#include "date.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    26
#include "strings.h"
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    27
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    28
5273
d9f707aa36a6 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    29
enum BuildVehicleWidgets {
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    30
	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    31
	BUILD_VEHICLE_WIDGET_CAPTION,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    32
	BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    33
	BUILD_VEHICLE_WIDGET_SORT_TEXT,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    34
	BUILD_VEHICLE_WIDGET_SORT_DROPDOWN,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    35
	BUILD_VEHICLE_WIDGET_LIST,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    36
	BUILD_VEHICLE_WIDGET_SCROLLBAR,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    37
	BUILD_VEHICLE_WIDGET_PANEL,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    38
	BUILD_VEHICLE_WIDGET_BUILD,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    39
	BUILD_VEHICLE_WIDGET_RENAME,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    40
	BUILD_VEHICLE_WIDGET_RESIZE,
5273
d9f707aa36a6 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    41
};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    42
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    43
static const Widget _build_vehicle_widgets[] = {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    44
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    45
	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    46
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    47
	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   215,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    48
	{    WWT_TEXTBTN,     RESIZE_LR,    14,   216,   227,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    49
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   215,    26,   121, 0x0,                     STR_NULL },
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    50
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   216,   227,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    51
	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   227,   122,   213, 0x0,                     STR_NULL },
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    52
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    53
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   214,   225, 0x0,                     STR_NULL },
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    54
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   215,   214,   225, 0x0,                     STR_NULL },
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    55
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   216,   227,   214,   225, 0x0,                     STR_RESIZE_BUTTON },
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    56
	{   WIDGETS_END},
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    57
};
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    58
5782
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    59
static void ResizeButtons(Window *w)
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    60
{
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    61
	/* Make the buttons in the bottom equal in size */
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    62
	w->widget[BUILD_VEHICLE_WIDGET_RENAME].right = w->widget[BUILD_VEHICLE_WIDGET_RESIZE].left - 1;
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    63
	w->widget[BUILD_VEHICLE_WIDGET_RENAME].left  = w->widget[BUILD_VEHICLE_WIDGET_RENAME].right / 2;
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    64
	w->widget[BUILD_VEHICLE_WIDGET_BUILD].right  = w->widget[BUILD_VEHICLE_WIDGET_RENAME].left - 1;
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    65
}
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
    66
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    67
/* Setup widget strings to fit the different types of vehicles */
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
    68
static void SetupWindowStrings(Window *w, byte type)
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    69
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    70
	switch (type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    71
		case VEH_Train:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    72
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_JUST_STRING;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    73
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_8843_TRAIN_VEHICLE_SELECTION;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    74
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_881F_BUILD_VEHICLE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    75
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    76
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_8820_RENAME;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    77
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    78
			break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    79
		case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    80
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9006_NEW_ROAD_VEHICLES;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    81
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9026_ROAD_VEHICLE_SELECTION;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    82
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9007_BUILD_VEHICLE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    83
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    84
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9034_RENAME;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    85
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    86
			break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    87
		case VEH_Ship:
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    88
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9808_NEW_SHIPS;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    89
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9825_SHIP_SELECTION_LIST_CLICK;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    90
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9809_BUILD_SHIP;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    91
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    92
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9836_RENAME;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    93
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    94
			break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    95
		case VEH_Aircraft:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    96
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_A005_NEW_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    97
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_A025_AIRCRAFT_SELECTION_LIST;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    98
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_A006_BUILD_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    99
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   100
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_A037_RENAME;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   101
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_A038_RENAME_AIRCRAFT_TYPE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   102
			break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   103
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   104
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   105
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   106
static bool _internal_sort_order; // descending/ascending
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   107
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   108
static byte _last_sort_criteria[]    = {0, 0, 0, 0};
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   109
static bool _last_sort_order[]       = {false, false, false, false};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   110
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   111
static int CDECL EngineNumberSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   112
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   113
	const EngineID va = *(const EngineID*)a;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   114
	const EngineID vb = *(const EngineID*)b;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   115
	int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   116
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   117
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   118
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   119
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   120
static int CDECL EngineIntroDateSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   121
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   122
	const int va = GetEngine(*(const EngineID*)a)->intro_date;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   123
	const int vb = GetEngine(*(const EngineID*)b)->intro_date;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   124
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   125
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   126
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   127
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   128
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   129
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   130
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   131
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   132
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   133
static int CDECL EngineNameSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   134
{
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   135
	static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   136
	static char     last_name[2][64] = { "\0", "\0" };
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   137
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   138
	const EngineID va = *(const EngineID*)a;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   139
	const EngineID vb = *(const EngineID*)b;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   140
	int r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   141
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   142
	if (va != last_engine[0]) {
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   143
		last_engine[0] = va;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   144
		GetString(last_name[0], GetCustomEngineName(va), lastof(last_name[0]));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   145
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   146
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   147
	if (vb != last_engine[1]) {
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   148
		last_engine[1] = vb;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   149
		GetString(last_name[1], GetCustomEngineName(vb), lastof(last_name[1]));
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   150
	}
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   151
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   152
	r = strcmp(last_name[0], last_name[1]); // sort by name
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   153
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   154
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   155
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   156
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   157
	}
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   158
	return _internal_sort_order ? -r : r;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   159
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   160
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   161
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   162
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   163
	const int va = GetEngine(*(const EngineID*)a)->reliability;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   164
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   165
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   166
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   167
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   168
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   169
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   170
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   171
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   172
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   173
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   174
/* Train sorting functions */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   175
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   176
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   177
	int va = RailVehInfo(*(const EngineID*)a)->base_cost;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   178
	int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   179
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   180
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   181
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   182
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   183
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   184
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   185
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   186
	int va = RailVehInfo(*(const EngineID*)a)->max_speed;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   187
	int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   188
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   189
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   190
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   191
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   192
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   193
static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   194
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   195
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   196
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   197
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   198
	int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   199
	int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   200
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   201
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   202
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   203
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   204
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   205
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   206
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   207
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   208
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   209
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   210
	int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   211
	int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   212
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   213
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   214
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   215
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   216
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   217
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   218
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   219
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   220
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   221
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   222
	/* Here we are using a few tricks to get the right sort.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   223
		* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   224
		* we will actually calculate cunning cost/power (to make it more than 1).
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   225
		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   226
		* Another thing is that both power and running costs should be doubled for multiheaded engines.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   227
		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   228
	int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   229
	int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   230
	int r = vb - va;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   231
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   232
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   233
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   234
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   235
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   236
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   237
	EngineID va = *(const EngineID*)a;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   238
	EngineID vb = *(const EngineID*)b;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   239
	int val_a = ((RailVehInfo(va)->flags & RVI_WAGON) != 0) ? 1 : 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   240
	int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   241
	int r = val_a - val_b;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   242
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   243
	/* Use EngineID to sort instead since we want consistent sorting */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   244
	if (r == 0) return EngineNumberSorter(a, b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   245
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   246
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   247
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   248
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   249
/* Aircraft sorting functions */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   250
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   251
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   252
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   253
	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   254
	const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   255
	int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   256
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   257
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   258
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   259
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   260
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   261
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   262
	const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   263
	const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   264
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   265
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   266
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   267
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   268
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   269
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   270
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   271
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   272
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   273
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   274
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   275
	const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   276
	const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   277
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   278
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   279
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   280
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   281
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   282
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   283
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   284
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   285
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   286
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   287
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   288
	const int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   289
	const int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   290
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   291
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   292
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   293
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   294
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   295
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   296
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   297
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   298
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   299
static EngList_SortTypeFunction * const _sorter[][9] = {{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   300
	/* Trains */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   301
	&EngineNumberSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   302
	&TrainEngineCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   303
	&TrainEngineSpeedSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   304
	&TrainEnginePowerSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   305
	&EngineIntroDateSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   306
	&EngineNameSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   307
	&TrainEngineRunningCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   308
	&TrainEnginePowerVsRunningCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   309
	&EngineReliabilitySorter,
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   310
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   311
	/* Road vehicles */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   312
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   313
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   314
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   315
	&EngineReliabilitySorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   316
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   317
	/* Ships */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   318
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   319
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   320
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   321
	&EngineReliabilitySorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   322
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   323
	/* Aircraft */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   324
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   325
	&AircraftEngineCostSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   326
	&AircraftEngineSpeedSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   327
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   328
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   329
	&AircraftEngineRunningCostSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   330
	&EngineReliabilitySorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   331
	&AircraftEngineCargoSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   332
}};
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   333
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   334
static const StringID _sort_listing[][10] = {{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   335
	/* Trains */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   336
	STR_ENGINE_SORT_ENGINE_ID,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   337
	STR_ENGINE_SORT_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   338
	STR_SORT_BY_MAX_SPEED,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   339
	STR_ENGINE_SORT_POWER,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   340
	STR_ENGINE_SORT_INTRO_DATE,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   341
	STR_SORT_BY_DROPDOWN_NAME,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   342
	STR_ENGINE_SORT_RUNNING_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   343
	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   344
	STR_SORT_BY_RELIABILITY,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   345
	INVALID_STRING_ID
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   346
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   347
	/* Road vehicles */
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   348
	STR_ENGINE_SORT_ENGINE_ID,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   349
	STR_ENGINE_SORT_INTRO_DATE,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   350
	STR_SORT_BY_DROPDOWN_NAME,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   351
	STR_SORT_BY_RELIABILITY,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   352
	INVALID_STRING_ID
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   353
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   354
	/* Ships */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   355
	STR_ENGINE_SORT_ENGINE_ID,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   356
	STR_ENGINE_SORT_INTRO_DATE,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   357
	STR_SORT_BY_DROPDOWN_NAME,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   358
	STR_SORT_BY_RELIABILITY,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   359
	INVALID_STRING_ID
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   360
},{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   361
	/* Aircraft */
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   362
	STR_ENGINE_SORT_ENGINE_ID,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   363
	STR_ENGINE_SORT_COST,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   364
	STR_SORT_BY_MAX_SPEED,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   365
	STR_ENGINE_SORT_INTRO_DATE,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   366
	STR_SORT_BY_DROPDOWN_NAME,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   367
	STR_ENGINE_SORT_RUNNING_COST,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   368
	STR_SORT_BY_RELIABILITY,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   369
	STR_ENGINE_SORT_CARGO_CAPACITY,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   370
	INVALID_STRING_ID
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   371
}};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   372
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   373
/* Draw rail wagon specific details */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   374
static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   375
{
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   376
	/* Purchase cost */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   377
	SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   378
	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   379
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   380
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   381
	/* Wagon weight - (including cargo) */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   382
	SetDParam(0, rvi->weight);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   383
	SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   384
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   385
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   386
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   387
	/* Wagon speed limit, displayed if above zero */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   388
	if (rvi->max_speed > 0 && _patches.wagon_speed_limits) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   389
		SetDParam(0, rvi->max_speed);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   390
		DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   391
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   392
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   393
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   394
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   395
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   396
/* Draw locomotive specific details */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   397
static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi, const Engine *e)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   398
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   399
	int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   400
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   401
	/* Purchase Cost - Engine weight */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   402
	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   403
	SetDParam(1, rvi->weight << multihead);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   404
	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   405
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   406
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   407
	/* Max speed - Engine power */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   408
	SetDParam(0, rvi->max_speed);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   409
	SetDParam(1, rvi->power << multihead);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   410
	DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   411
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   412
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   413
	/* Max tractive effort - not applicable if old acceleration or maglev */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   414
	if (_patches.realistic_acceleration && e->railtype != RAILTYPE_MAGLEV) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   415
		SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   416
		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   417
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   418
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   419
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   420
	/* Running cost */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   421
	SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   422
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   423
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   424
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   425
	/* Powered wagons power - Powered wagons extra weight */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   426
	if (rvi->pow_wag_power != 0) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   427
		SetDParam(0, rvi->pow_wag_power);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   428
		SetDParam(1, rvi->pow_wag_weight);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   429
		DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   430
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   431
	};
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   432
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   433
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   434
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   435
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   436
/* Draw road vehicle specific details */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   437
static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   438
{
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   439
	bool refittable = (_engine_info[engine_number].refit_mask != 0);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   440
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   441
	/* Purchase cost - Max speed */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   442
	SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   443
	SetDParam(1, rvi->max_speed / 2);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   444
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   445
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   446
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   447
	/* Running cost */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   448
	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   449
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   450
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   451
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   452
	/* Cargo type + capacity */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   453
	SetDParam(0, rvi->cargo_type);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   454
	SetDParam(1, rvi->capacity);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   455
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   456
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   457
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   458
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   459
	return y;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   460
}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   461
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   462
/* Draw ship specific details */
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   463
static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   464
{
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   465
	/* Purchase cost - Max speed */
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   466
	SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   467
	SetDParam(1, svi->max_speed / 2);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   468
	DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   469
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   470
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   471
	/* Cargo type + capacity */
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   472
	SetDParam(0, svi->cargo_type);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   473
	SetDParam(1, svi->capacity);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   474
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   475
	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   476
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   477
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   478
	/* Running cost */
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   479
	SetDParam(0, svi->running_cost * _price.ship_running >> 8);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   480
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   481
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   482
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   483
	return y;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   484
}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   485
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   486
/* Draw aircraft specific details */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   487
static int DrawVehiclePurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   488
{
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   489
	CargoID cargo;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   490
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   491
	/* Purchase cost - Max speed */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   492
	SetDParam(0, avi->base_cost * (_price.aircraft_base>>3)>>5);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   493
	SetDParam(1, avi->max_speed * 128 / 10);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   494
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   495
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   496
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   497
	/* Cargo capacity */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   498
	cargo = FindFirstRefittableCargo(engine_number);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   499
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   500
		SetDParam(0, avi->passenger_capacity);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   501
		SetDParam(1, avi->mail_capacity);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   502
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   503
	} else {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   504
		/* Note, if the default capacity is selected by the refit capacity
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   505
		* callback, then the capacity shown is likely to be incorrect. */
4896
f86350aaaaa5 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4807
diff changeset
   506
		SetDParam(0, cargo);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   507
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, engine_number));
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   508
		SetDParam(2, STR_9842_REFITTABLE);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   509
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   510
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   511
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   512
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   513
	/* Running cost */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   514
	SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   515
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   516
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   517
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   518
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   519
}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   520
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   521
/**
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   522
 * Draw the purchase info details of a vehicle at a given location.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   523
 * @param x,y location where to draw the info
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   524
 * @param w how wide are the text allowed to be (size of widget/window to Draw in)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   525
 * @param engine_number the engine of which to draw the info of
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   526
 */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   527
void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   528
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   529
	const Engine *e = GetEngine(engine_number);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   530
	YearMonthDay ymd;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   531
	ConvertDateToYMD(e->intro_date, &ymd);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   532
	bool refitable = false;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   533
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   534
	switch (e->type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   535
		case VEH_Train: {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   536
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   537
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   538
			if (rvi->flags & RVI_WAGON) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   539
				y = DrawVehiclePurchaseInfo(x, y, engine_number, rvi);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   540
				refitable = true;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   541
			} else {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   542
				y = DrawVehiclePurchaseInfo(x, y, engine_number, rvi, e);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   543
				refitable = (rvi->capacity > 0);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   544
			}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   545
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   546
			/* Cargo type + capacity, or N/A */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   547
			if (rvi->capacity == 0) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   548
				SetDParam(0, CT_INVALID);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   549
				SetDParam(2, STR_EMPTY);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   550
			} else {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   551
				int multihead = (rvi->flags & RVI_MULTIHEAD ? 1 : 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   552
				SetDParam(0, rvi->cargo_type);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   553
				SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   554
				SetDParam(2, STR_9842_REFITTABLE);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   555
			}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   556
			DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   557
			y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   558
		}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   559
			break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   560
		case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   561
			y = DrawVehiclePurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   562
			refitable = true;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   563
			break;
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   564
		case VEH_Ship: {
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   565
			const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   566
			y = DrawVehiclePurchaseInfo(x, y, engine_number, svi);
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   567
			refitable = svi->refittable;
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   568
		} break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   569
		case VEH_Aircraft:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   570
			y = DrawVehiclePurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number));
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   571
			refitable = true;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   572
			break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   573
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   574
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   575
	/* Draw details, that applies to all types except rail wagons */
5787
49f49e4b3e3e (svn r8339) -Fix(r8331): MSVC seems to be a little more strict (or less intelligent) then other compilers when it comes to operator precedence.
belugas
parents: 5786
diff changeset
   576
	if (e->type != VEH_Train || !(RailVehInfo(engine_number)->flags & RVI_WAGON)) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   577
		/* Design date - Life length */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   578
		SetDParam(0, ymd.year);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   579
		SetDParam(1, e->lifelength);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   580
		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   581
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   582
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   583
		/* Reliability */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   584
		SetDParam(0, e->reliability * 100 >> 16);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   585
		DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   586
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   587
	}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   588
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   589
	/* Additional text from NewGRF */
4930
708801d486c6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   590
	y += ShowAdditionalText(x, y, w, engine_number);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   591
	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   592
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   593
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   594
/* Figure out what train EngineIDs to put in the list */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   595
static void GenerateBuildTrainList(Window *w)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   596
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   597
	EngineID eid, sel_id;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   598
	int num_engines = 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   599
	int num_wagons  = 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   600
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   601
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   602
	bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   603
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   604
	EngList_RemoveAll(&bv->eng_list);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   605
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   606
	/* Make list of all available train engines and wagons.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   607
		* Also check to see if the previously selected engine is still available,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   608
		* and if not, reset selection to INVALID_ENGINE. This could be the case
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   609
	* when engines become obsolete and are removed */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   610
	for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   611
		const Engine *e = GetEngine(eid);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   612
		const RailVehicleInfo *rvi = RailVehInfo(eid);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   613
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   614
		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   615
		if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   616
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   617
		EngList_Add(&bv->eng_list, eid);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   618
		if ((rvi->flags & RVI_WAGON) == 0) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   619
			num_engines++;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   620
		} else {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   621
			num_wagons++;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   622
		}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   623
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   624
		if (eid == bv->sel_engine) sel_id = eid;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   625
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   626
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   627
	bv->sel_engine = sel_id;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   628
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   629
	// make engines first, and then wagons, sorted by ListPositionOfEngine()
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   630
	_internal_sort_order = false;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   631
	EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   632
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   633
	// and then sort engines
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   634
	_internal_sort_order = bv->descending_sort_order;
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   635
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], 0, num_engines);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   636
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   637
	// and finally sort wagons
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   638
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], num_engines, num_wagons);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   639
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   640
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   641
/* Figure out what road vehicle EngineIDs to put in the list */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   642
static void GenerateBuildRoadVehList(Window *w)
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   643
{
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   644
	EngineID eid, sel_id;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   645
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   646
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   647
	EngList_RemoveAll(&bv->eng_list);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   648
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   649
	sel_id = INVALID_ENGINE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   650
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   651
	for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   652
		if (!IsEngineBuildable(eid, VEH_Road, _local_player)) continue;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   653
		EngList_Add(&bv->eng_list, eid);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   654
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   655
		if (eid == bv->sel_engine) sel_id = eid;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   656
	}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   657
	bv->sel_engine = sel_id;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   658
}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   659
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   660
/* Figure out what ship EngineIDs to put in the list */
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   661
static void GenerateBuildShipList(Window *w)
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   662
{
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   663
	EngineID eid, sel_id;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   664
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   665
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   666
	EngList_RemoveAll(&bv->eng_list);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   667
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   668
	sel_id = INVALID_ENGINE;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   669
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   670
	for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) {
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   671
		if (!IsEngineBuildable(eid, VEH_Ship, _local_player)) continue;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   672
		EngList_Add(&bv->eng_list, eid);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   673
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   674
		if (eid == bv->sel_engine) sel_id = eid;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   675
	}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   676
	bv->sel_engine = sel_id;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   677
}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   678
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   679
/* Figure out what aircraft EngineIDs to put in the list */
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   680
static void GenerateBuildAircraftList(Window *w)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   681
{
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   682
	EngineID eid, sel_id;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   683
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   684
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   685
	EngList_RemoveAll(&bv->eng_list);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   686
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   687
	/* Make list of all available planes.
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   688
	 * Also check to see if the previously selected plane is still available,
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   689
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   690
	 * when planes become obsolete and are removed */
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   691
	sel_id = INVALID_ENGINE;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   692
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
5215
b8fb685df4c5 (svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents: 5201
diff changeset
   693
		if (IsEngineBuildable(eid, VEH_Aircraft, _local_player)) {
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   694
			EngList_Add(&bv->eng_list, eid);
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   695
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   696
			if (eid == bv->sel_engine) sel_id = eid;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   697
		}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   698
	}
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   699
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   700
	bv->sel_engine = sel_id;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   701
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   702
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   703
/* Generate the list of vehicles */
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   704
static void GenerateBuildList(Window *w)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   705
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   706
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   707
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   708
	switch (bv->vehicle_type) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   709
		case VEH_Train:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   710
			GenerateBuildTrainList(w);
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   711
			return; // trains should not reach the last sorting
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   712
		case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   713
			GenerateBuildRoadVehList(w);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   714
			break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   715
		case VEH_Ship:
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   716
			GenerateBuildShipList(w);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   717
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   718
		case VEH_Aircraft:
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   719
			GenerateBuildAircraftList(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   720
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   721
	}
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   722
	_internal_sort_order = bv->descending_sort_order;
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   723
	EngList_Sort(&bv->eng_list, _sorter[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria]);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   724
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   725
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   726
static void DrawBuildVehicleWindow(Window *w)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   727
{
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   728
	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   729
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   730
	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   731
5201
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   732
	SetVScrollCount(w, EngList_Count(&bv->eng_list));
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   733
	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   734
	DrawWindowWidgets(w);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   735
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   736
	{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   737
		int x = 2;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   738
		int y = 27;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   739
		EngineID selected_id = bv->sel_engine;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   740
		uint16 position = w->vscroll.pos;
5201
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   741
		uint16 max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   742
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   743
		switch (bv->vehicle_type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   744
			case VEH_Train:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   745
				for (; position < max; position++, y += 14) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   746
					const EngineID engine = bv->eng_list[position];
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   747
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   748
					DrawString(x + 59, y + 2, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   749
					DrawTrainEngine(x + 29, y + 6, engine, GetEnginePalette(engine, _local_player));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   750
				}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   751
				break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   752
			case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   753
				for (; position < max; position++, y += 14) {
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   754
					const EngineID engine = bv->eng_list[position];
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   755
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   756
					DrawString(x + 58, y + 2, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   757
					DrawRoadVehEngine(x + 28, y + 6, engine, GetEnginePalette(engine, _local_player));
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   758
				}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   759
				break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   760
			case VEH_Ship:
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   761
				for (; position < max; position++, y += 24) {
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   762
					const EngineID engine = bv->eng_list[position];
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   763
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   764
					DrawString(x + 75, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   765
					DrawShipEngine(x + 35, y + 10, engine, GetEnginePalette(engine, _local_player));
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   766
				}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   767
				break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   768
			case VEH_Aircraft:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   769
				for (; position < max; position++, y += 24) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   770
					const EngineID engine = bv->eng_list[position];
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   771
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   772
					DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   773
					DrawAircraftEngine(x + 29, y + 10, engine, GetEnginePalette(engine, _local_player));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   774
				}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   775
				break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   776
		}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   777
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   778
		if (selected_id != INVALID_ENGINE) {
4930
708801d486c6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   779
			const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   780
			DrawVehiclePurchaseInfo(x, wi->top + 1, wi->right - wi->left - 2, selected_id);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   781
		}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   782
	}
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   783
	DrawString(85, 15, _sort_listing[VehTypeToIndex(bv->vehicle_type)][bv->sort_criteria], 0x10);
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   784
	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   785
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   786
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   787
static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   788
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   789
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   790
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   791
	switch (e->we.click.widget) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   792
		case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
5199
9a75b853ad22 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   793
			bv->descending_sort_order ^= true;
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   794
			_last_sort_order[VehTypeToIndex(bv->vehicle_type)] = bv->descending_sort_order;
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   795
			bv->regenerate_list = true;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   796
			SetWindowDirty(w);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   797
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   798
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   799
		case BUILD_VEHICLE_WIDGET_LIST: {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   800
			uint i = (e->we.click.pt.y - 26) / GetVehicleListHeight(bv->vehicle_type) + w->vscroll.pos;
5201
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   801
			uint num_items = EngList_Count(&bv->eng_list);
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   802
			bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   803
			SetWindowDirty(w);
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   804
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   805
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   806
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   807
		case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   808
			ShowDropDownMenu(w, _sort_listing[VehTypeToIndex(bv->vehicle_type)], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   809
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   810
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   811
		case BUILD_VEHICLE_WIDGET_BUILD: {
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   812
			EngineID sel_eng = bv->sel_engine;
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   813
			if (sel_eng != INVALID_ENGINE) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   814
				switch (bv->vehicle_type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   815
					case VEH_Train:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   816
						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   817
								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   818
						break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   819
					case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   820
						DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   821
						break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   822
					case VEH_Ship:
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   823
						DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   824
						break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   825
					case VEH_Aircraft:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   826
						DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   827
						break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   828
				}
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   829
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   830
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   831
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   832
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   833
		case BUILD_VEHICLE_WIDGET_RENAME: {
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   834
			EngineID sel_eng = bv->sel_engine;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   835
			if (sel_eng != INVALID_ENGINE) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   836
				StringID str = STR_NULL;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   837
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   838
				bv->rename_engine = sel_eng;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   839
				switch (bv->vehicle_type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   840
					case VEH_Train:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   841
					case VEH_Road:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   842
					case VEH_Ship:     str = STR_9838_RENAME_SHIP_TYPE;          break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   843
					case VEH_Aircraft: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   844
				}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   845
				ShowQueryString(GetCustomEngineName(sel_eng), str, 31, 160, w, CS_ALPHANUMERAL);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   846
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   847
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   848
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   849
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   850
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   851
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   852
static void NewVehicleWndProc(Window *w, WindowEvent *e)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   853
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   854
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   855
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   856
	switch (e->event) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   857
		case WE_INVALIDATE_DATA:
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   858
			bv->regenerate_list = true;
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   859
			SetWindowDirty(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   860
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   861
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   862
		case WE_DESTROY:
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   863
			EngList_Destroy(&bv->eng_list);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   864
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   865
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   866
		case WE_PAINT:
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   867
			if (bv->regenerate_list) {
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   868
				bv->regenerate_list = false;
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   869
				GenerateBuildList(w);
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   870
			}
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   871
			DrawBuildVehicleWindow(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   872
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   873
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   874
		case WE_CLICK:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   875
			BuildVehicleClickEvent(w, e);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   876
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   877
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   878
		case WE_ON_EDIT_TEXT: {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   879
			if (e->we.edittext.str[0] != '\0') {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   880
				StringID str = STR_NULL;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   881
				_cmd_text = e->we.edittext.str;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   882
				switch (bv->vehicle_type) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   883
					case VEH_Train:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   884
					case VEH_Road:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   885
					case VEH_Ship:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   886
					case VEH_Aircraft: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   887
				}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   888
				DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(str));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   889
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   890
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   891
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   892
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   893
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   894
			if (bv->sort_criteria != e->we.dropdown.index) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   895
				bv->sort_criteria = e->we.dropdown.index;
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   896
				_last_sort_criteria[VehTypeToIndex(bv->vehicle_type)] = bv->sort_criteria;
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   897
				bv->regenerate_list = true;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   898
			}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   899
			SetWindowDirty(w);
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   900
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   901
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   902
		case WE_RESIZE:
5782
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
   903
			if (e->we.sizing.diff.x != 0) ResizeButtons(w);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   904
			if (e->we.sizing.diff.y == 0) break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   905
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   906
			w->vscroll.cap += e->we.sizing.diff.y / GetVehicleListHeight(bv->vehicle_type);
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   907
			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   908
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   909
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   910
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   911
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   912
static const WindowDesc _build_vehicle_desc = {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   913
	WDP_AUTO, WDP_AUTO, 228, 226,
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   914
	WC_BUILD_VEHICLE,0,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   915
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   916
	_build_vehicle_widgets,
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   917
	NewVehicleWndProc
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   918
};
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   919
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   920
void ShowBuildVehicleWindow(TileIndex tile, byte type)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   921
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   922
	buildvehicle_d *bv;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   923
	Window *w;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   924
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   925
	assert(IsPlayerBuildableVehicleType(type));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   926
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   927
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   928
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   929
	w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   930
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   931
	if (w == NULL) return;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   932
5199
9a75b853ad22 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   933
	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   934
	w->resize.step_height = GetVehicleListHeight(type);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   935
	w->vscroll.cap = w->resize.step_height == 24 ? 4 : 8;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   936
	w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   937
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   938
	bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   939
	EngList_Create(&bv->eng_list);
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   940
	bv->sel_engine      = INVALID_ENGINE;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   941
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   942
	bv->vehicle_type    = type;
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   943
	bv->regenerate_list = false;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   944
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   945
	bv->sort_criteria         = _last_sort_criteria[VehTypeToIndex(type)];
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   946
	bv->descending_sort_order = _last_sort_order[VehTypeToIndex(type)];
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   947
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   948
	switch (type) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   949
		case VEH_Train:
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   950
			WP(w,buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   951
			ResizeWindow(w, 0, 16);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   952
			break;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   953
		case VEH_Road:
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   954
			ResizeWindow(w, 20, 16);
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   955
		case VEH_Ship:
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   956
			ResizeWindow(w, 27, 0);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   957
			break;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   958
		case VEH_Aircraft:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   959
			AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   960
			bv->filter.acc_planes = acc_planes;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   961
			ResizeWindow(w, 12, 0);
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   962
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   963
	}
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   964
	SetupWindowStrings(w, type);
5782
e0251c1fb22c (svn r8334) -Fix (r8331): build window buttons now both resize as intended
bjarni
parents: 5781
diff changeset
   965
	ResizeButtons(w);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   966
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   967
	w->resize.width  = w->width;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   968
	w->resize.height = w->height;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   969
5781
404262bfa03d (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 5780
diff changeset
   970
	GenerateBuildList(w); // generate the list, since we need it in the next line
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   971
	/* Select the first engine in the list as default when opening the window */
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   972
	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   973
}