train_gui.c
author bjarni
Tue, 10 Oct 2006 08:34:14 +0000
changeset 4794 23b5ee70e87e
parent 4792 a6fa5fc79715
child 4813 96eb742c98a0
permissions -rw-r--r--
(svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2147
diff changeset
     6
#include "functions.h"
4041
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 4012
diff changeset
     7
#include "rail_map.h"
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
     8
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 460
diff changeset
     9
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 601
diff changeset
    10
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "engine.h"
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
    20
#include "vehicle_gui.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    21
#include "depot.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
    22
#include "train.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2959
diff changeset
    23
#include "newgrf_engine.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4251
diff changeset
    24
#include "date.h"
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    25
#include "strings.h"
420
d4aa4a1df3c6 (svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents: 395
diff changeset
    26
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    27
typedef enum BuildTrainWidgets {
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    28
	BUILD_TRAIN_WIDGET_CLOSEBOX = 0,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    29
	BUILD_TRAIN_WIDGET_CAPTION,
4794
23b5ee70e87e (svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
bjarni
parents: 4792
diff changeset
    30
	BUILD_TRAIN_WIDGET_SORT_ASSENDING_DESCENDING,
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    31
	BUILD_TRAIN_WIDGET_SORT_TEXT,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    32
	BUILD_TRAIN_WIDGET_SORT_DROPDOWN,
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    33
	BUILD_TRAIN_WIDGET_LIST,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    34
	BUILD_TRAIN_WIDGET_SCROLLBAR,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    35
	BUILD_TRAIN_WIDGET_PANEL,
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    36
	BUILD_TRAIN_WIDGET_ENGINES,
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    37
	BUILD_TRAIN_WIDGET_WAGONS,
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    38
	BUILD_TRAIN_WIDGET_BOTH,
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    39
	BUILD_TRAIN_WIDGET_BUILD,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    40
	BUILD_TRAIN_WIDGET_RENAME,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    41
	BUILD_TRAIN_WIDGET_RESIZE,
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    42
} BuildTrainWidget;
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
    43
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    44
static const Widget _new_rail_vehicle_widgets[] = {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    45
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    46
	{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   227,     0,    13, STR_JUST_STRING,        STR_018C_WINDOW_TITLE_DRAG_THIS},
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    47
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,            STR_SORT_ORDER_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    48
	{      WWT_PANEL,   RESIZE_NONE,    14,    81,   215,    14,    25, 0x0,                    STR_SORT_CRITERIA_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    49
	{    WWT_TEXTBTN,   RESIZE_NONE,    14,   216,   227,    14,    25, STR_0225,               STR_SORT_CRITERIA_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    50
	{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    26,   137, 0x801,                  STR_8843_TRAIN_VEHICLE_SELECTION},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    51
	{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    26,   137, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    52
	{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   138,   209, 0x0,                    STR_NULL},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    53
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,    76,   210,   221, STR_BLACK_ENGINES,      STR_BUILD_TRAIN_ENGINES_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    54
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,    77,   151,   210,   221, STR_BLACK_WAGONS,       STR_BUILD_TRAIN_WAGONS_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    55
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   152,   227,   210,   221, STR_BLACK_BOTH,         STR_BUILD_TRAIN_BOTH_TIP},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    56
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   107,   222,   233, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    57
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   108,   215,   222,   233, STR_8820_RENAME,        STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    58
	{  WWT_RESIZEBOX,     RESIZE_TB,    14,   216,   227,   222,   233, 0x0,                    STR_RESIZE_BUTTON},
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    59
	{   WIDGETS_END},
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    60
};
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
    61
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    62
static bool _internal_sort_order; // descending/ascending
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    63
static byte _last_sort_criteria = 0;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    64
static bool _last_sort_order = false;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    65
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    66
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    67
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    68
static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    69
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    70
	const EngineID va = *(const EngineID*)a;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    71
	const EngineID vb = *(const EngineID*)b;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    72
	int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    73
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    74
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    75
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    76
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    77
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    78
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    79
	const int va = RailVehInfo(*(const EngineID*)a)->base_cost;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    80
	const int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    81
	int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    82
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    83
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    84
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    85
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    86
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    87
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    88
	const int va = RailVehInfo(*(const EngineID*)a)->max_speed;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    89
	const int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    90
	const int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    91
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    92
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    93
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    94
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    95
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    96
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    97
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    98
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
    99
static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   100
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   101
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   102
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   103
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   104
	const int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   105
	const int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   106
	const int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   107
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   108
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   109
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   110
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   111
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   112
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   113
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   114
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   115
static int CDECL TrainEngineIntroDateSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   116
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   117
	const int va = GetEngine(*(const EngineID*)a)->intro_date;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   118
	const int vb = GetEngine(*(const EngineID*)b)->intro_date;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   119
	const int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   120
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   121
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   122
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   123
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   124
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   125
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   126
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   127
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   128
static EngineID _last_engine; // cached vehicle to hopefully speed up name-sorting
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   129
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   130
static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   131
static int CDECL TrainEngineNameSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   132
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   133
	const EngineID va = *(const EngineID*)a;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   134
	const EngineID vb = *(const EngineID*)b;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   135
	char buf1[64] = "\0";
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   136
	int r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   137
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   138
	SetDParam(0, GetCustomEngineName(va));
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   139
	GetString(buf1, STR_JUST_STRING);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   140
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   141
	if (vb != _last_engine) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   142
		_last_engine = vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   143
		_bufcache[0] = '\0';
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   144
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   145
		SetDParam(0, GetCustomEngineName(vb));
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   146
		GetString(_bufcache, STR_JUST_STRING);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   147
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   148
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   149
	r =  strcmp(buf1, _bufcache); // sort by name
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   150
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   151
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   152
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   153
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   154
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   155
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   156
	return (_internal_sort_order & 1) ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   157
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   158
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   159
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   160
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   161
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   162
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   163
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   164
	const int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   165
	const int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   166
	const int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   167
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   168
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   169
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   170
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   171
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   172
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   173
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   174
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   175
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   176
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   177
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   178
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   179
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   180
	/* Here we are using a few tricks to get the right sort.
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   181
	 * We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   182
	 * we will actually calculate cunning cost/power (to make it more than 1).
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   183
	 * Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   184
	 * Another thing is that both power and running costs should be doubled for multiheaded engines.
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   185
	 * Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   186
	const int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / rvi_a->power;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   187
	const int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / rvi_b->power;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   188
	const int r = vb - va;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   189
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   190
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   191
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   192
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   193
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   194
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   195
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   196
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   197
static int CDECL TrainEngineReliabilitySorter(const void *a, const void *b)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   198
{
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   199
	const int va = GetEngine(*(const EngineID*)a)->reliability;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   200
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   201
	const int r = va - vb;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   202
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   203
	if (r == 0) {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   204
		/* Use EngineID to sort instead since we want consistent sorting */
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   205
		return TrainEngineNumberSorter(a, b);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   206
	}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   207
	return _internal_sort_order ? -r : r;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   208
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   209
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   210
static VehicleSortListingTypeFunction* const _engine_sorter[] = {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   211
	&TrainEngineNumberSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   212
	&TrainEngineCostSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   213
	&TrainEngineSpeedSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   214
	&TrainEnginePowerSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   215
	&TrainEngineIntroDateSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   216
	&TrainEngineNameSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   217
	&TrainEngineRunningCostSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   218
	&TrainEnginePowerVsRunningCostSorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   219
	&TrainEngineReliabilitySorter,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   220
};
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   221
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   222
static const StringID _engine_sort_listing[] = {
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   223
	STR_ENGINE_SORT_ENGINE_ID,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   224
	STR_ENGINE_SORT_COST,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   225
	STR_SORT_BY_MAX_SPEED,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   226
	STR_ENGINE_SORT_POWER,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   227
	STR_ENGINE_SORT_INTRO_DATE,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   228
	STR_SORT_BY_DROPDOWN_NAME,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   229
	STR_ENGINE_SORT_RUNNING_COST,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   230
	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   231
	STR_SORT_BY_RELIABILITY,
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   232
	INVALID_STRING_ID
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   233
};
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   234
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   235
/**
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   236
 * Draw the purchase info details of train engine at a given location.
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   237
 * @param x,y location where to draw the info
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   238
 * @param engine_number the engine of which to draw the info of
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   239
 */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   240
void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   241
{
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   242
	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   243
	const Engine *e = GetEngine(engine_number);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   244
	int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   245
	YearMonthDay ymd;
4288
393de75451b1 (svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents: 4286
diff changeset
   246
	ConvertDateToYMD(e->intro_date, &ymd);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   247
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   248
	/* Purchase Cost - Engine weight */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   249
	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   250
	SetDParam(1, rvi->weight << multihead);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   251
	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   252
	y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   253
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   254
	/* Max speed - Engine power */
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   255
	SetDParam(0, rvi->max_speed);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   256
	SetDParam(1, rvi->power << multihead);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   257
	DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   258
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   259
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   260
	/* Running cost */
2840
9038b4ab8c9a (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2822
diff changeset
   261
	SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   262
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   263
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   264
1908
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   265
	/* Powered wagons power - Powered wagons extra weight */
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   266
	if (rvi->pow_wag_power != 0) {
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   267
		SetDParam(0, rvi->pow_wag_power);
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   268
		SetDParam(1, rvi->pow_wag_weight);
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   269
		DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   270
		y += 10;
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   271
	};
2fa391fed79a (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   272
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   273
	/* Cargo type + capacity, or N/A */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   274
	SetDParam(0, STR_8838_N_A);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   275
	SetDParam(2, STR_EMPTY);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   276
	if (rvi->capacity != 0) {
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   277
		SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
4737
287bc9b53ec9 (svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents: 4712
diff changeset
   278
		SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   279
		SetDParam(2, STR_9842_REFITTABLE);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   280
	}
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   281
	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   282
	y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   283
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   284
	/* Design date - Life length */
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4288
diff changeset
   285
	SetDParam(0, ymd.year);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   286
	SetDParam(1, e->lifelength);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   287
	DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   288
	y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   289
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   290
	/* Reliability */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   291
	SetDParam(0, e->reliability * 100 >> 16);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   292
	DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   293
	y += 10;
3651
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   294
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   295
	/* Additional text from NewGRF */
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   296
	// XXX 227 will become a calculated width...
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   297
	y += ShowAdditionalText(x, y, 227, engine_number);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   298
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   299
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   300
/**
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   301
 * Draw the purchase info details of a train wagon at a given location.
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   302
 * @param x,y location where to draw the info
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   303
 * @param engine_number the engine of which to draw the info of
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   304
 */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   305
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   306
{
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   307
	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3384
diff changeset
   308
	bool refittable = (EngInfo(engine_number)->refit_mask != 0);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   309
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   310
	/* Purchase cost */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   311
	SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   312
	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   313
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   314
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   315
	/* Wagon weight - (including cargo) */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   316
	SetDParam(0, rvi->weight);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   317
	SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   318
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   319
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   320
3685
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   321
	/* Cargo type + capacity, or N/A */
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   322
	SetDParam(0, STR_8838_N_A);
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   323
	SetDParam(2, STR_EMPTY);
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   324
	if (rvi->capacity != 0) {
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   325
		SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
4737
287bc9b53ec9 (svn r6649) - Codechange: Show more correct capacity of articulated wagons in the train purchase list.
peter1138
parents: 4712
diff changeset
   326
		SetDParam(1, rvi->capacity * (CountArticulatedParts(engine_number) + 1));
3685
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   327
		SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
82a5112081d4 (svn r4610) - If a wagon has a capacity of 0 (zero), display it in the purchase list as N/A.
peter1138
parents: 3651
diff changeset
   328
	}
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   329
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   330
	y += 10;
2443
dd16304c477d (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   331
dd16304c477d (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   332
	/* Wagon speed limit, displayed if above zero */
2456
2317dd6f4b19 (svn r2982) Newgrf: Added patch option for wagon speed limits. This is enabled by default.
peter1138
parents: 2443
diff changeset
   333
	if (rvi->max_speed > 0 && _patches.wagon_speed_limits) {
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   334
		SetDParam(0, rvi->max_speed);
2443
dd16304c477d (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   335
		DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0);
dd16304c477d (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   336
		y += 10;
dd16304c477d (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   337
	}
3651
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   338
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   339
	/* Additional text from NewGRF */
f2998a6a190d (svn r4562) - NewGRF: Add additional vehicle text to train engine and wagon purchase information. Other vehicle types to come.
peter1138
parents: 3491
diff changeset
   340
	y += ShowAdditionalText(x, y, 227, engine_number);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   341
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   343
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   345
	Vehicle *v, *found;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4049
diff changeset
   347
	if (!success) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	// find a locomotive in the depot.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	found = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	FOR_ALL_VEHICLES(v) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   352
		if (v->type == VEH_Train && IsFrontEngine(v) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
				v->tile == tile &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
				v->u.rail.track == 0x80) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4049
diff changeset
   355
			if (found != NULL) return; // must be exactly one.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
			found = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	// if we found a loco,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	if (found != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		found = GetLastVehicleInChain(found);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		// put the new wagon at the end of the loco.
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3919
diff changeset
   364
		DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
   365
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   369
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   371
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   373
	if (!success) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   374
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3919
diff changeset
   375
	v = GetVehicle(_new_vehicle_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	if (tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		RestoreVehicleOrders(v, _backup_orders_data);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	ShowTrainViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
3887
ece644bbf459 (svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents: 3884
diff changeset
   383
void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   384
{
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3919
diff changeset
   385
	if (success) ShowTrainViewWindow(GetVehicle(_new_vehicle_id));
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   386
}
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   387
static void engine_drawing_loop(const EngineID *engines, const uint16 engine_count,
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   388
								const int x, int *y, const EngineID sel, EngineID *position, const int16 show_max)
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   389
{
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   390
	for (; (*position) < min(engine_count, show_max); (*position)++) {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   391
		EngineID i = engines[*position];
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   392
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   393
		DrawString(x + 59, *y + 2, GetCustomEngineName(i), sel == i ? 0xC : 0x10);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   394
		DrawTrainEngine(x + 29, *y + 6, i, GetEnginePalette(i, _local_player));
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   395
		*y += 14;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   396
	}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   397
}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   398
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   399
static inline void ExtendEngineListSize(const EngineID **engine_list, uint16 *engine_list_length, uint16 step_size)
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   400
{
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   401
	*engine_list_length = min(*engine_list_length + step_size, NUM_TRAIN_ENGINES);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   402
	*engine_list = realloc((void*)*engine_list, (*engine_list_length) * sizeof((*engine_list)[0]));
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   403
}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   404
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   405
static void GenerateBuildList(EngineID **engines, uint16 *num_engines, EngineID **wagons, uint16 *num_wagons, RailType railtype)
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   406
{
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   407
	uint16 engine_length = *num_engines;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   408
	uint16 wagon_length  = *num_wagons;
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   409
	EngineID j;
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   410
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   411
	(*num_engines) = 0;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   412
	(*num_wagons)  = 0;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   413
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   414
	if (engines == NULL) ExtendEngineListSize((const EngineID**)engines, &engine_length, 25);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   415
	if (wagons  == NULL) ExtendEngineListSize((const EngineID**)wagons,  &wagon_length,  25);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   416
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   417
	for (j = 0; j < NUM_TRAIN_ENGINES; j++) {
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   418
		EngineID i = GetRailVehAtPosition(j);
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   419
		const Engine *e = GetEngine(i);
539
7e16a61c51ce (svn r923) Forgot s/rail_vehinfo/RailVehInfo/
tron
parents: 538
diff changeset
   420
		const RailVehicleInfo *rvi = RailVehInfo(i);
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   421
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   422
		if (!HasPowerOnRail(e->railtype, railtype)) continue;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   423
		if (!IsEngineBuildable(i, VEH_Train)) continue;
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   424
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   425
		if (rvi->flags & RVI_WAGON) {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   426
			if (*num_wagons == wagon_length) ExtendEngineListSize((const EngineID**)wagons, &wagon_length, 5);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   427
			(*wagons)[(*num_wagons)++] = i;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   428
		} else {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   429
			if (*num_engines == engine_length) ExtendEngineListSize((const EngineID**)engines, &engine_length, 5);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   430
			(*engines)[(*num_engines)++] = i;
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   431
		}
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   432
	}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   433
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   434
	/* Reduce array sizes if they are too big */
4788
76ed308037b1 (svn r6709) -Fix r6679: [build train window] solved an issue that could lead to trailing empty blocks in the list array
bjarni
parents: 4786
diff changeset
   435
	if (*num_engines != engine_length) *engines = realloc((void*)*engines, (*num_engines) * sizeof((*engines)[0]));
76ed308037b1 (svn r6709) -Fix r6679: [build train window] solved an issue that could lead to trailing empty blocks in the list array
bjarni
parents: 4786
diff changeset
   436
	if (*num_wagons  != wagon_length)  *wagons  = realloc((void*)*wagons,  (*num_wagons)  * sizeof((*wagons)[0]));
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   437
}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   438
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   439
static void SortTrainBuildList(Window *w)
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   440
{
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   441
	_internal_sort_order = WP(w,buildvehicle_d).decenting_sort_order;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   442
	qsort((void*)WP(w, buildvehicle_d).list_a, WP(w, buildvehicle_d).list_a_length, sizeof(WP(w, buildvehicle_d).list_a[0]),
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   443
		  _engine_sorter[WP(w,buildvehicle_d).sort_criteria]);
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   444
}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   445
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   446
static void DrawTrainBuildWindow(Window *w)
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   447
{
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   448
	int x = 1;
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   449
	int y = 27;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   450
	EngineID position = w->vscroll.pos;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   451
	EngineID selected_id = WP(w,buildvehicle_d).sel_engine;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   452
	int max = w->vscroll.pos + w->vscroll.cap;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   453
	uint16 scrollcount = 0;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   454
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   455
	SetWindowWidgetDisabledState(w, BUILD_TRAIN_WIDGET_BUILD, w->window_number == 0); // Disable unless we got a depot to build in
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   456
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   457
	/* Draw the clicked engine/wagon/both button pressed and unpress the other two */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   458
	SetWindowWidgetLoweredState(w, BUILD_TRAIN_WIDGET_ENGINES, WP(w,buildvehicle_d).show_engine_button == 1);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   459
	SetWindowWidgetLoweredState(w, BUILD_TRAIN_WIDGET_WAGONS,  WP(w,buildvehicle_d).show_engine_button == 2);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   460
	SetWindowWidgetLoweredState(w, BUILD_TRAIN_WIDGET_BOTH,    WP(w,buildvehicle_d).show_engine_button == 3);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   461
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   462
	if (WP(w,buildvehicle_d).data_invalidated) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   463
		GenerateBuildList(&WP(w, buildvehicle_d).list_a, &WP(w, buildvehicle_d).list_a_length, &WP(w, buildvehicle_d).list_b, &WP(w, buildvehicle_d).list_b_length, WP(w,buildvehicle_d).railtype);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   464
		WP(w,buildvehicle_d).data_invalidated = false;
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   465
		SortTrainBuildList(w);
4767
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   466
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   467
		/* Make sure that the selected engine is still in the list*/
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   468
		if (WP(w,buildvehicle_d).sel_engine != INVALID_ENGINE) {
4767
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   469
			int i;
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   470
			bool found = false;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   471
			if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   472
				for (i = 0; i < WP(w, buildvehicle_d).list_a_length; i++) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   473
					if (WP(w,buildvehicle_d).sel_engine != WP(w, buildvehicle_d).list_a[i]) continue;
4767
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   474
					found = true;
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   475
					break;
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   476
				}
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   477
			}
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   478
			if (!found && HASBIT(WP(w,buildvehicle_d).show_engine_button, 1)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   479
				for (i = 0; i < WP(w, buildvehicle_d).list_b_length; i++) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   480
					if (WP(w,buildvehicle_d).sel_engine != WP(w, buildvehicle_d).list_b[i]) continue;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   481
					found = true;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   482
					break;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   483
				}
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   484
			}
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   485
			if (!found) WP(w,buildvehicle_d).sel_engine = INVALID_ENGINE;
4767
df84b7f59e5b (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   486
		}
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4765
diff changeset
   487
	}
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   488
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   489
	if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0)) scrollcount += WP(w, buildvehicle_d).list_a_length;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   490
	if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 1)) scrollcount += WP(w, buildvehicle_d).list_b_length;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   491
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   492
	SetVScrollCount(w, scrollcount);
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   493
	SetDParam(0, WP(w,buildvehicle_d).railtype + STR_881C_NEW_RAIL_VEHICLES);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   494
	DrawWindowWidgets(w);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   495
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   496
	if (selected_id == INVALID_ENGINE && scrollcount != 0) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   497
		if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0) && WP(w, buildvehicle_d).list_a_length != 0) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   498
			selected_id = WP(w, buildvehicle_d).list_a[0];
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   499
		} else {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   500
			selected_id = WP(w, buildvehicle_d).list_b[0];
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   501
		}
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   502
		WP(w,buildvehicle_d).sel_engine = selected_id;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   503
	}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   504
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   505
	/* Draw the engines */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   506
	if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   507
		engine_drawing_loop(WP(w, buildvehicle_d).list_a, WP(w, buildvehicle_d).list_a_length, x, &y, selected_id, &position, max);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   508
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   509
		/* Magically set the number 0 line to the one right after the last engine
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   510
		* This way the line numbers fit the indexes in the wagon array */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   511
		position -= WP(w, buildvehicle_d).list_a_length;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   512
		max      -= WP(w, buildvehicle_d).list_a_length;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   513
	}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   514
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   515
	/* Draw the wagons */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   516
	if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 1)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   517
		engine_drawing_loop(WP(w, buildvehicle_d).list_b,  WP(w, buildvehicle_d).list_b_length,  x, &y, selected_id, &position, max);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   518
	}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   519
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   520
	if (selected_id != INVALID_ENGINE) {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   521
		const RailVehicleInfo *rvi = RailVehInfo(selected_id);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   522
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   523
		if (rvi->flags & RVI_WAGON) {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   524
			DrawTrainWagonPurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1, selected_id);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   525
		} else {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   526
			DrawTrainEnginePurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1, selected_id);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   527
		}
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   528
	}
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   529
	DrawString(85, 15, _engine_sort_listing[WP(w,buildvehicle_d).sort_criteria], 0x10);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   530
	DoDrawString(WP(w,buildvehicle_d).decenting_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
524
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   531
}
bcbcedbf5ccd (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   532
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   535
	switch (e->event) {
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   536
		case WE_CREATE:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   537
			WP(w, buildvehicle_d).list_a_length = 0;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   538
			WP(w, buildvehicle_d).list_b_length = 0;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   539
			WP(w, buildvehicle_d).list_a        = NULL;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   540
			WP(w, buildvehicle_d).list_b        = NULL;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   541
			WP(w, buildvehicle_d).show_engine_button   = 3;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   542
			WP(w, buildvehicle_d).data_invalidated     = true;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   543
			WP(w, buildvehicle_d).sel_engine           = INVALID_ENGINE;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   544
			WP(w, buildvehicle_d).sort_criteria        = _last_sort_criteria;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   545
			WP(w, buildvehicle_d).decenting_sort_order = _last_sort_order;
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4765
diff changeset
   546
			break;
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4765
diff changeset
   547
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4765
diff changeset
   548
		case WE_INVALIDATE_DATA:
4792
a6fa5fc79715 (svn r6714) -Codechange: replaced a direct manipulation of windows with InvalidateWindowData() in rail_cmd.c
bjarni
parents: 4790
diff changeset
   549
			if (w->window_number != 0) WP(w,buildvehicle_d).railtype = GetRailType(w->window_number);
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   550
			WP(w,buildvehicle_d).data_invalidated = true;
4792
a6fa5fc79715 (svn r6714) -Codechange: replaced a direct manipulation of windows with InvalidateWindowData() in rail_cmd.c
bjarni
parents: 4790
diff changeset
   551
			SetWindowDirty(w);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   552
			break;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   553
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   554
		case WE_DESTROY:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   555
			free((void*)WP(w, buildvehicle_d).list_a);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   556
			free((void*)WP(w, buildvehicle_d).list_b);
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   557
			break;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   558
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   559
		case WE_PAINT:
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   560
			DrawTrainBuildWindow(w);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   561
			break;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   562
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   564
		case WE_CLICK: {
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   565
			switch (e->we.click.widget) {
4794
23b5ee70e87e (svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
bjarni
parents: 4792
diff changeset
   566
				case BUILD_TRAIN_WIDGET_SORT_ASSENDING_DESCENDING:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   567
					WP(w,buildvehicle_d).decenting_sort_order = !WP(w,buildvehicle_d).decenting_sort_order;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   568
					_last_sort_order = WP(w,buildvehicle_d).decenting_sort_order;
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   569
					SortTrainBuildList(w);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   570
					SetWindowDirty(w);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   571
					break;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   572
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   573
				case BUILD_TRAIN_WIDGET_SORT_TEXT: case BUILD_TRAIN_WIDGET_SORT_DROPDOWN:/* Select sorting criteria dropdown menu */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   574
					ShowDropDownMenu(w, _engine_sort_listing, WP(w,buildvehicle_d).sort_criteria, BUILD_TRAIN_WIDGET_SORT_DROPDOWN, 0, 0);
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   575
					return;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   576
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   577
				case BUILD_TRAIN_WIDGET_LIST: {
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   578
					uint i = ((e->we.click.pt.y - 26) / 14) + w->vscroll.pos;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   579
					if (i < (uint)(WP(w, buildvehicle_d).list_a_length + WP(w, buildvehicle_d).list_b_length)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   580
						if (i < WP(w, buildvehicle_d).list_a_length && HASBIT(WP(w,buildvehicle_d).show_engine_button, 0)) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   581
							WP(w,buildvehicle_d).sel_engine = WP(w, buildvehicle_d).list_a[i];
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   582
						} else {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   583
							WP(w,buildvehicle_d).sel_engine = WP(w, buildvehicle_d).list_b[i - (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0) ? WP(w, buildvehicle_d).list_a_length : 0)];
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   584
						}
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   585
						SetWindowDirty(w);
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   586
					}
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   587
				} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   589
				case BUILD_TRAIN_WIDGET_ENGINES:
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   590
				case BUILD_TRAIN_WIDGET_WAGONS:
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   591
				case BUILD_TRAIN_WIDGET_BOTH: {
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   592
					/* First we need to figure out the new show_engine_wagon setting
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   593
					 * Because the button widgets are ordered as they are (in a row), we can calculate as following:
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   594
					 * engines = bit 0 (1 for set), wagons bit 1 (2 for set), both (2 | 1 = 3)
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   595
					 * Those numbers are the same as the clicked button - BUILD_TRAIN_WIDGET_ENGINES + 1 */
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   596
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   597
					byte click_state = e->we.click.widget - BUILD_TRAIN_WIDGET_ENGINES + 1;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   598
					if (WP(w,buildvehicle_d).show_engine_button == click_state) break; // We clicked the pressed button
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   599
					WP(w,buildvehicle_d).sel_engine = INVALID_ENGINE;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   600
					WP(w,buildvehicle_d).show_engine_button = click_state;
4765
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   601
					w->vscroll.pos = 0;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   602
					SetWindowDirty(w);
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   603
					}
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   604
					break;
d109bfb2cc73 (svn r6679) -Feature: [train build window] added filter for wagons, engines or both in the display
bjarni
parents: 4764
diff changeset
   605
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   606
				case BUILD_TRAIN_WIDGET_BUILD: {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   607
					EngineID sel_eng = WP(w,buildvehicle_d).sel_engine;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   608
					if (sel_eng != INVALID_ENGINE)
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   609
						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   610
				}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   612
				case BUILD_TRAIN_WIDGET_RENAME: {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   613
					EngineID sel_eng = WP(w,buildvehicle_d).sel_engine;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   614
					if (sel_eng != INVALID_ENGINE) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   615
						WP(w,buildvehicle_d).rename_engine = sel_eng;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   616
						ShowQueryString(GetCustomEngineName(sel_eng),
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   617
										STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL);
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   618
					}
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   619
				} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		} break;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   622
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   623
		case WE_ON_EDIT_TEXT: {
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   624
			if (e->we.edittext.str[0] != '\0') {
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   625
				_cmd_text = e->we.edittext.str;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   626
				DoCommandP(0, WP(w,buildvehicle_d).rename_engine, 0, NULL,
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   627
					CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   628
			}
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 919
diff changeset
   629
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   631
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   632
			if (WP(w,buildvehicle_d).sort_criteria != e->we.dropdown.index) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   633
				WP(w,buildvehicle_d).sort_criteria = e->we.dropdown.index;
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   634
				_last_sort_criteria = e->we.dropdown.index;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   635
				SortTrainBuildList(w);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   636
			}
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   637
			SetWindowDirty(w);
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   638
			break;
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   639
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   640
		case WE_RESIZE: {
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   641
			if (e->we.sizing.diff.y == 0) break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   642
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   643
			w->vscroll.cap += e->we.sizing.diff.y / 14;
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   644
			w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   645
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   648
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
static const WindowDesc _new_rail_vehicle_desc = {
4770
7092e6b90693 (svn r6684) -Feature: [train build window] added sorting options for the engines
bjarni
parents: 4769
diff changeset
   650
	-1, -1, 228, 234,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	WC_BUILD_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   652
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	_new_rail_vehicle_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	NewRailVehicleWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
4442
9f8bb348d58f (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4434
diff changeset
   657
void ShowBuildTrainWindow(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	w = AllocateWindowDesc(&_new_rail_vehicle_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	w->window_number = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	w->vscroll.cap = 8;
4764
79341214c15d (svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents
bjarni
parents: 4737
diff changeset
   666
	w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   667
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   668
	w->resize.step_height = 14;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3948
diff changeset
   669
	w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   670
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	if (tile != 0) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   672
		w->caption_color = GetTileOwner(tile);
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   673
		WP(w,buildvehicle_d).railtype = GetRailType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
		w->caption_color = _local_player;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4788
diff changeset
   676
		WP(w,buildvehicle_d).railtype = GetBestRailtype(GetPlayer(_local_player));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
2593
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   680
/**
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   681
 * Get the number of pixels for the given wagon length.
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   682
 * @param len Length measured in 1/8ths of a standard wagon.
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   683
 * @return Number of pixels across.
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   684
 */
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents: 4635
diff changeset
   685
int WagonLengthToPixels(int len) {
3845
af6eb0103fed (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3844
diff changeset
   686
	return (len * _traininfo_vehicle_width) / 8;
2593
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   687
}
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   688
4442
9f8bb348d58f (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4434
diff changeset
   689
void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
{
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   691
	DrawPixelInfo tmp_dpi, *old_dpi;
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   692
	int dx = -(skip * 8) / _traininfo_vehicle_width;
4049
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   693
	/* Position of highlight box */
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   694
	int highlight_l = 0;
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   695
	int highlight_r = 0;
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   696
4429
b4eb6d97996f (svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents: 4426
diff changeset
   697
	if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return;
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   698
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   699
	count = (count * 8) / _traininfo_vehicle_width;
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   700
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   701
	old_dpi = _cur_dpi;
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   702
	_cur_dpi = &tmp_dpi;
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   703
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	do {
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   705
		int width = v->u.rail.cached_veh_length;
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   706
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   707
		if (dx + width > 0) {
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   708
			if (dx <= count) {
3049
d6109b5fd55d (svn r3631) - 2cc: Remove use of some temporary variables and perform minor optimization in the form of the ternary operator.
peter1138
parents: 3040
diff changeset
   709
				PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
4049
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   710
				DrawSprite(GetTrainImage(v, DIR_W) | pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   711
				if (v->index == selection) {
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   712
					/* Set the highlight position */
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   713
					highlight_l = WagonLengthToPixels(dx) + 1;
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   714
					highlight_r = WagonLengthToPixels(dx + width) + 1;
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   715
				}
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   716
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
		}
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   718
		dx += width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
2593
ccb101f0439c (svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents: 2570
diff changeset
   720
		v = v->next;
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   721
	} while (dx < count && v != NULL);
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   722
4049
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   723
	if (highlight_l != highlight_r) {
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   724
		/* Draw the highlight. Now done after drawing all the engines, as
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   725
		 * the next engine after the highlight could overlap it. */
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   726
		DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY);
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   727
	}
d65bf8f154bc (svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents: 4041
diff changeset
   728
3919
b64f70fcca85 (svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents: 3887
diff changeset
   729
	_cur_dpi = old_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
2275
11a1dac70c45 (svn r2799) Make the only two non-const widget lists const
tron
parents: 2261
diff changeset
   732
static const Widget _train_view_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   733
{   WWT_CLOSEBOX,  RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,        STR_018B_CLOSE_WINDOW },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   734
{    WWT_CAPTION, RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_882E,        STR_018C_WINDOW_TITLE_DRAG_THIS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   735
{  WWT_STICKYBOX,    RESIZE_LR, 14, 238, 249,   0,  13, 0x0,             STR_STICKY_BUTTON },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   736
{      WWT_PANEL,    RESIZE_RB, 14,   0, 231,  14, 121, 0x0,             STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   737
{          WWT_6,    RESIZE_RB, 14,   2, 229,  16, 119, 0x0,             STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   738
{ WWT_PUSHIMGBTN,   RESIZE_RTB, 14,   0, 237, 122, 133, 0x0,             STR_8846_CURRENT_TRAIN_ACTION_CLICK },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   739
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  14,  31, 0x2AB,           STR_8848_CENTER_MAIN_VIEW_ON_TRAIN },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   740
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  32,  49, 0x2AD,           STR_8849_SEND_TRAIN_TO_DEPOT },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   741
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  50,  67, 0x2B1,           STR_884A_FORCE_TRAIN_TO_PROCEED },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   742
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  68,  85, 0x2CB,           STR_884B_REVERSE_DIRECTION_OF_TRAIN },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   743
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  86, 103, 0x2B2,           STR_8847_SHOW_TRAIN_S_ORDERS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   744
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249, 104, 121, 0x2B3,           STR_884C_SHOW_TRAIN_DETAILS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   745
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  68,  85, 0x2B4,           STR_RAIL_REFIT_VEHICLE_TO_CARRY },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   746
{ WWT_PUSHIMGBTN,    RESIZE_LR, 14, 232, 249,  32,  49, SPR_CLONE_TRAIN, STR_CLONE_TRAIN_INFO },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   747
{      WWT_PANEL,   RESIZE_LRB, 14, 232, 249, 122, 121, 0x0,             STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   748
{  WWT_RESIZEBOX,  RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0,             STR_NULL },
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   749
{ WIDGETS_END }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   752
static void ShowTrainDetailsWindow(const Vehicle *v);
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   753
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
static void TrainViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
{
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1790
diff changeset
   756
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	case WE_PAINT: {
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1790
diff changeset
   758
		const Vehicle *v, *u;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		StringID str;
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   760
		bool is_localplayer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   762
		v = GetVehicle(w->window_number);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   763
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   764
		is_localplayer = v->owner == _local_player;
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   765
		SetWindowWidgetDisabledState(w,  7, !is_localplayer);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   766
		SetWindowWidgetDisabledState(w,  8, !is_localplayer);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   767
		SetWindowWidgetDisabledState(w,  9, !is_localplayer);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   768
		SetWindowWidgetDisabledState(w, 12, !is_localplayer);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   769
		SetWindowWidgetDisabledState(w, 13, !is_localplayer);
1387
bc0131072af9 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   770
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   771
		if (is_localplayer) {
2867
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   772
			/* See if any vehicle can be refitted */
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   773
			for (u = v; u != NULL; u = u->next) {
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3384
diff changeset
   774
				if (EngInfo(u->engine_type)->refit_mask != 0 ||
2867
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   775
						(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   776
					EnableWindowWidget(w, 12);
2867
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   777
					/* We have a refittable carriage, bail out */
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   778
					break;
91ee491df4ec (svn r3415) - Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator. (thanks to UnderBuilder for pointing this out)
peter1138
parents: 2840
diff changeset
   779
				}
1387
bc0131072af9 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   780
			}
bc0131072af9 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   781
		}
bc0131072af9 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   782
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
		/* draw widgets & caption */
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   784
		SetDParam(0, v->string_id);
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   785
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
		if (v->u.rail.crash_anim_pos != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
			str = STR_8863_CRASHED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		} else if (v->breakdown_ctr == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			str = STR_885C_BROKEN_DOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		} else if (v->vehstatus & VS_STOPPED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
			if (v->u.rail.last_speed == 0) {
4251
e8f69de723e1 (svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents: 4171
diff changeset
   794
				if (v->u.rail.cached_power == 0) {
e8f69de723e1 (svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents: 4171
diff changeset
   795
					str = STR_TRAIN_NO_POWER;
e8f69de723e1 (svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents: 4171
diff changeset
   796
				} else {
e8f69de723e1 (svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents: 4171
diff changeset
   797
					str = STR_8861_STOPPED;
e8f69de723e1 (svn r5853) -Fix: [elrails] FS#178 Electric Trains can leave Conventional Depot
bjarni
parents: 4171
diff changeset
   798
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
			} else {
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   800
				SetDParam(0, v->u.rail.last_speed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
				str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
		} else {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   804
			switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
			case OT_GOTO_STATION: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
4527
fa30d19685c2 (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   807
				SetDParam(0, v->current_order.dest);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   808
				SetDParam(1, v->u.rail.last_speed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
			case OT_GOTO_DEPOT: {
4527
fa30d19685c2 (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   812
				Depot *dep = GetDepot(v->current_order.dest);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   813
				SetDParam(0, dep->town_index);
4633
cf6c2f173030 (svn r6497) -Fix r6165: Vehicles heading for depots when their orders contained "service in depot" displayed the stopping in depot string
bjarni
parents: 4547
diff changeset
   814
				if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
4412
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   815
					str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed;
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   816
				} else {
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   817
					str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed;
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   818
				}
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   819
				SetDParam(1, v->u.rail.last_speed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
			case OT_LOADING:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			case OT_LEAVESTATION:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
				str = STR_882F_LOADING_UNLOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 382
diff changeset
   827
			case OT_GOTO_WAYPOINT: {
4527
fa30d19685c2 (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   828
				SetDParam(0, v->current_order.dest);
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 382
diff changeset
   829
				str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   830
				SetDParam(1, v->u.rail.last_speed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   833
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
				if (v->num_orders == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
					str = STR_NO_ORDERS + _patches.vehicle_speed;
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
   837
					SetDParam(0, v->u.rail.last_speed);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4049
diff changeset
   838
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
					str = STR_EMPTY;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4049
diff changeset
   840
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
2103
a2b3106d33d5 (svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents: 2084
diff changeset
   845
		/* draw the flag plus orders */
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   846
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
2113
be2f07df0dfa (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2103
diff changeset
   847
		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
	}	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
	case WE_CLICK: {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   852
		int wid = e->we.click.widget;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   853
		Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   855
		switch (wid) {
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   856
		case 5: /* start/stop train */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   857
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
			break;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
   859
		case 6: /* center main view */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
			ScrollMainWindowTo(v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
			break;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
   862
		case 7: /* goto depot */
601
3d15c18e3a8e (svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents: 588
diff changeset
   863
			/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
4506
e6a56518135c (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4495
diff changeset
   864
			DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   866
		case 8: /* force proceed */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   867
			DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   869
		case 9: /* reverse direction */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   870
			DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   872
		case 10: /* show train orders */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
			ShowOrdersWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   875
		case 11: /* show train details */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
			ShowTrainDetailsWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   878
		case 12:
4712
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4709
diff changeset
   879
			ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
			break;
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   881
		case 13:
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   882
			DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   883
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   887
	case WE_RESIZE:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   888
		w->viewport->width          += e->we.sizing.diff.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   889
		w->viewport->height         += e->we.sizing.diff.y;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   890
		w->viewport->virtual_width  += e->we.sizing.diff.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   891
		w->viewport->virtual_height += e->we.sizing.diff.y;
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   892
		break;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   893
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	case WE_DESTROY:
338
37500d4214f3 (svn r514) -Fix: [1053397] Refit Train Window Stays Open
tron
parents: 243
diff changeset
   895
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	case WE_MOUSELOOP: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   901
		const Vehicle *v = GetVehicle(w->window_number);
4702
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   902
		bool train_stopped = CheckTrainStoppedInDepot(v)  >= 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
4702
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   904
		/* Widget 7 (send to depot) must be hidden if the train is already stopped in hangar.
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   905
		 * Widget 13 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   906
		 * This sytem allows to have two buttons, on top of each other.
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   907
		 * The same system applies to widget 9 and 12, reverse direction and refit*/
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   908
		if (train_stopped != IsWindowWidgetHidden(w, 7) || train_stopped == IsWindowWidgetHidden(w, 13)) {
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   909
			SetWindowWidgetHiddenState(w,  7, train_stopped);  // send to depot
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   910
			SetWindowWidgetHiddenState(w,  9, train_stopped);  // reverse direction
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   911
			SetWindowWidgetHiddenState(w, 12, !train_stopped); // refit
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   912
			SetWindowWidgetHiddenState(w, 13, !train_stopped); // clone
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
static const WindowDesc _train_view_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	-1,-1, 250, 134,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	WC_VEHICLE_VIEW,0,
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   924
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
	_train_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	TrainViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   929
void ShowTrainViewWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
   931
	Window *w = AllocateWindowDescFront(&_train_view_desc,v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   933
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
		w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
   939
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
{
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   941
	if (v->cargo_cap != 0) {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   942
		uint num = v->cargo_count;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   943
		StringID str = STR_8812_EMPTY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		if (num != 0) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   946
			SetDParam(0, v->cargo_type);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   947
			SetDParam(1, num);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   948
			SetDParam(2, v->cargo_source);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
			str = STR_8813_FROM;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
		DrawString(x, y, str, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
   955
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
{
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   957
	if (RailVehInfo(v->engine_type)->flags & RVI_WAGON) {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   958
		SetDParam(0, GetCustomEngineName(v->engine_type));
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   959
		SetDParam(1, v->value);
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   960
		DrawString(x, y, STR_882D_VALUE, 0x10);
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   961
	} else {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   962
		SetDParam(0, GetCustomEngineName(v->engine_type));
4329
0e6e689f66e7 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4299
diff changeset
   963
		SetDParam(1, v->build_year);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   964
		SetDParam(2, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
		DrawString(x, y, STR_882C_BUILT_VALUE, 0x10);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   966
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
   969
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	if (v->cargo_cap != 0) {
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   972
		SetDParam(0, _cargoc.names_long[v->cargo_type]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   973
		SetDParam(1, v->cargo_cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
		DrawString(x, y, STR_013F_CAPACITY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
static void DrawTrainDetailsWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
	byte det_tab = WP(w, traindetails_d).tab;
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   982
	const Vehicle* v;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   983
	const Vehicle* u;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   984
	AcceptedCargo act_cargo;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   985
	AcceptedCargo max_cargo;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   986
	uint i;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   987
	int num;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   988
	int x;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   989
	int y;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   990
	int sel;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	num = 0;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   993
	u = v = GetVehicle(w->window_number);
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   994
	if (det_tab == 3) { // Total cargo tab
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   995
		for (i = 0; i < lengthof(act_cargo); i++) {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   996
			act_cargo[i] = 0;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
   997
			max_cargo[i] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1000
		do {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1001
			act_cargo[u->cargo_type] += u->cargo_count;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1002
			max_cargo[u->cargo_type] += u->cargo_cap;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1003
		} while ((u = GetNextVehicle(u)) != NULL);
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1004
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1005
		/* Set scroll-amount seperately from counting, as to not compute num double
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1006
		 * for more carriages of the same type
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1007
		 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
		for (i = 0; i != NUM_CARGO; i++) {
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1009
			if (max_cargo[i] > 0) num++; // only count carriages that the train has
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		}
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1011
		num++; // needs one more because first line is description string
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1012
	} else {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1013
		do {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1014
			num++;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1015
		} while ((u = GetNextVehicle(u)) != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	SetVScrollCount(w, num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1020
	DisableWindowWidget(w, det_tab + 9);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1021
	SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1023
	/* disable service-scroller when interval is set to disabled */
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1024
	SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1025
	SetWindowWidgetDisabledState(w, 7, !_patches.servint_trains);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 22
diff changeset
  1026
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1027
	SetDParam(0, v->string_id);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1028
	SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1031
	SetDParam(1, v->age / 366);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1032
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
	x = 2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1034
2252
6df2bfd7a077 (svn r2772) Simplify the age notice in the vehicle details window
tron
parents: 2244
diff changeset
  1035
	SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1036
	SetDParam(2, v->max_age / 366);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1037
	SetDParam(3, GetTrainRunningCost(v) >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3401
diff changeset
  1040
	SetDParam(2, v->u.rail.cached_max_speed);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1041
	SetDParam(1, v->u.rail.cached_power);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1042
	SetDParam(0, v->u.rail.cached_weight);
3401
3eb83140e401 (svn r4211) - Removed measuring units from the names of two strings.
peter1138
parents: 3393
diff changeset
  1043
	DrawString(x, 25, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1045
	SetDParam(0, v->profit_this_year);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1046
	SetDParam(1, v->profit_last_year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1049
	SetDParam(0, 100 * (v->reliability>>8) >> 8);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1050
	SetDParam(1, v->breakdowns_since_last_service);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1053
	SetDParam(0, v->service_interval);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1054
	SetDParam(1, v->date_of_last_service);
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1055
	DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	y = 57;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	sel = w->vscroll.pos;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1059
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	// draw the first 3 details tabs
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	if (det_tab != 3) {
2822
3685b5c83c57 (svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents: 2819
diff changeset
  1062
		x = 1;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
  1063
		for (;;) {
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1064
			if (--sel < 0 && sel >= -w->vscroll.cap) {
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1065
				int dx = 0;
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1066
				int px;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1067
				int py;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1068
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1069
				u = v;
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1070
				do {
3844
85105d1abf48 (svn r4868) - Codechange: in the train detail window, don't call DrawTrainImage() for each row, as we already loop to find the vehicles to
peter1138
parents: 3785
diff changeset
  1071
					PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
85105d1abf48 (svn r4868) - Codechange: in the train detail window, don't call DrawTrainImage() for each row, as we already loop to find the vehicles to
peter1138
parents: 3785
diff changeset
  1072
					DrawSprite(GetTrainImage(u, DIR_W) | pal, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
2602
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1073
					dx += u->u.rail.cached_veh_length;
1a6561c9a408 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1074
					u = u->next;
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
  1075
				} while (u != NULL && IsArticulatedPart(u));
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1076
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1077
				px = x + WagonLengthToPixels(dx) + 2;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1078
				py = y + 2;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1079
				switch (det_tab) {
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1080
					default: NOT_REACHED();
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1081
					case 0: TrainDetailsCargoTab(   v, px, py); break;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1082
					case 1: TrainDetailsInfoTab(    v, px, py); break;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1083
					case 2: TrainDetailsCapacityTab(v, px, py); break;
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1084
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
				y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
			}
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1087
			v = GetNextVehicle(v);
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1088
			if (v == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
		}
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1090
	} else {
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1091
		// draw total cargo tab
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1093
		for (i = 0; i != NUM_CARGO; i++) {
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1094
			if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
				y += 14;
4492
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1096
				SetDParam(0, i);            // {CARGO} #1
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1097
				SetDParam(1, act_cargo[i]); // {CARGO} #2
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1098
				SetDParam(2, i);            // {SHORTCARGO} #1
7c67249f083c (svn r6277) Clean up the train details drawing routine
tron
parents: 4456
diff changeset
  1099
				SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
2822
3685b5c83c57 (svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents: 2819
diff changeset
  1100
				DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
			}
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1102
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
static void TrainDetailsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
{
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
  1108
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		DrawTrainDetailsWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
		int mod;
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
  1114
		const Vehicle *v;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1115
		switch (e->we.click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
		case 2: /* name train */
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1117
			v = GetVehicle(w->window_number);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1118
			SetDParam(0, v->unitnumber);
4299
91f5d2bedcff (svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents: 4293
diff changeset
  1119
			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
			break;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1121
		case 6: /* inc serv interval */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 22
diff changeset
  1122
			mod = _ctrl_pressed? 5 : 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
			goto do_change_service_int;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
		case 7: /* dec serv interval */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 22
diff changeset
  1126
			mod = _ctrl_pressed? -5 : -10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
do_change_service_int:
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1128
			v = GetVehicle(w->window_number);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 22
diff changeset
  1129
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
  1130
			mod = GetServiceIntervalClamped(mod + v->service_interval);
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1658
diff changeset
  1131
			if (mod == v->service_interval) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1132
2819
f25fb6ee397f (svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents: 2806
diff changeset
  1133
			DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		/* details buttons*/
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1136
		case 9:  // Cargo
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1137
		case 10: // Information
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1138
		case 11: // Capacities
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4429
diff changeset
  1139
		case 12: // Total cargo
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1140
			EnableWindowWidget(w,  9);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1141
			EnableWindowWidget(w, 10);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1142
			EnableWindowWidget(w, 11);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1143
			EnableWindowWidget(w, 12);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1144
			EnableWindowWidget(w, e->we.click.widget);
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1145
			WP(w,traindetails_d).tab = e->we.click.widget - 9;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2520
diff changeset
  1151
	case WE_ON_EDIT_TEXT:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1152
		if (e->we.edittext.str[0] != '\0') {
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1153
			_cmd_text = e->we.edittext.str;
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
  1154
			DoCommandP(0, w->window_number, 0, NULL,
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
  1155
				CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
  1156
		}
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2520
diff changeset
  1157
		break;
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1158
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1159
	case WE_RESIZE:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1160
		if (e->we.sizing.diff.y == 0) break;
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1161
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
  1162
		w->vscroll.cap += e->we.sizing.diff.y / 14;
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4541
diff changeset
  1163
		w->widget[4].data = (w->vscroll.cap << 8) + 1;
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1164
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
static const Widget _train_details_widgets[] = {
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1169
{   WWT_CLOSEBOX, RESIZE_NONE,   14,   0,  10,   0,  13, STR_00C5,             STR_018B_CLOSE_WINDOW},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1170
{    WWT_CAPTION, RESIZE_NONE,   14,  11, 329,   0,  13, STR_8802_DETAILS,     STR_018C_WINDOW_TITLE_DRAG_THIS},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1171
{ WWT_PUSHTXTBTN, RESIZE_NONE,   14, 330, 369,   0,  13, STR_01AA_NAME,        STR_8867_NAME_TRAIN},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1172
{      WWT_PANEL, RESIZE_NONE,   14,   0, 369,  14,  55, 0x0,                  STR_NULL},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1173
{     WWT_MATRIX, RESIZE_BOTTOM, 14,   0, 357,  56, 139, 0x601,                STR_NULL},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1174
{  WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 358, 369,  56, 139, 0x0,                  STR_0190_SCROLL_BAR_SCROLLS_LIST},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1175
{ WWT_PUSHTXTBTN, RESIZE_TB,     14,   0,  10, 140, 145, STR_0188,             STR_884D_INCREASE_SERVICING_INTERVAL},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1176
{ WWT_PUSHTXTBTN, RESIZE_TB,     14,   0,  10, 146, 151, STR_0189,             STR_884E_DECREASE_SERVICING_INTERVAL},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1177
{      WWT_PANEL, RESIZE_TB,     14,  11, 369, 140, 151, 0x0,                  STR_NULL},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1178
{ WWT_PUSHTXTBTN, RESIZE_TB,     14,   0,  89, 152, 163, STR_013C_CARGO,       STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1179
{ WWT_PUSHTXTBTN, RESIZE_TB,     14,  90, 178, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1180
{ WWT_PUSHTXTBTN, RESIZE_TB,     14, 179, 268, 152, 163, STR_013E_CAPACITIES,  STR_8851_SHOW_CAPACITIES_OF_EACH},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1181
{ WWT_PUSHTXTBTN, RESIZE_TB,     14, 269, 357, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO},
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1182
{  WWT_RESIZEBOX, RESIZE_TB,     14, 358, 369, 152, 163, 0x0,                  STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
  1183
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
static const WindowDesc _train_details_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	-1,-1, 370, 164,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1190
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
	_train_details_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
	TrainDetailsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4088
diff changeset
  1196
static void ShowTrainDetailsWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
	VehicleID veh = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1204
	_alloc_wnd_parent_num = veh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
	w = AllocateWindowDesc(&_train_details_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	w->window_number = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	w->vscroll.cap = 6;
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4541
diff changeset
  1210
	w->widget[4].data = (w->vscroll.cap << 8) + 1;
2959
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1211
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1212
	w->resize.step_height = 14;
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1213
	w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */
0a9e35c5d7a3 (svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents: 2958
diff changeset
  1214
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	WP(w,traindetails_d).tab = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
}