train_gui.c
author truelight
Sun, 29 Jan 2006 20:03:50 +0000
changeset 2920 a582cd504686
parent 2867 66a9c4e27e34
child 2951 2db3adee7736
permissions -rw-r--r--
(svn r3476) -Fix: fixed a warning from the OSX compiler, it is bogus, but oh well
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (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
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2147
diff changeset
     6
#include "functions.h"
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
     7
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 460
diff changeset
     8
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 601
diff changeset
     9
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "engine.h"
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
    19
#include "vehicle_gui.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    20
#include "depot.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
    21
#include "train.h"
420
d3a089648ec3 (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
    22
d3a089648ec3 (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
    23
int _traininfo_vehicle_pitch = 0;
d3a089648ec3 (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
    24
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    25
/**
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    26
 * Draw the purchase info details of train engine at a given location.
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    27
 * @param x,y location where to draw the info
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    28
 * @param engine_number the engine of which to draw the info of
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    29
 */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    30
void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    31
{
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    32
	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
    33
	const Engine* e = GetEngine(engine_number);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    34
	int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    35
	YearMonthDay ymd;
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    36
	ConvertDayToYMD(&ymd, e->intro_date);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    37
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    38
	/* Purchase Cost - Engine weight */
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    39
	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    40
	SetDParam(1, rvi->weight << multihead);
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    41
	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    42
	y += 10;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    43
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    44
	/* Max speed - Engine power */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    45
	SetDParam(0, rvi->max_speed * 10 >> 4);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    46
	SetDParam(1, rvi->power << multihead);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    47
	DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    48
	y += 10;
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    49
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    50
	/* Running cost */
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2822
diff changeset
    51
	SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    52
	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    53
	y += 10;
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    54
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    55
	/* Powered wagons power - Powered wagons extra weight */
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    56
	if (rvi->pow_wag_power != 0) {
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    57
		SetDParam(0, rvi->pow_wag_power);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    58
		SetDParam(1, rvi->pow_wag_weight);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    59
		DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0);
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    60
		y += 10;
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    61
	};
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    62
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    63
	/* Cargo type + capacity, or N/A */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    64
	SetDParam(0, STR_8838_N_A);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    65
	SetDParam(2, STR_EMPTY);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    66
	if (rvi->capacity != 0) {
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
    67
		SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    68
		SetDParam(1, rvi->capacity << multihead);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    69
		SetDParam(2, STR_9842_REFITTABLE);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    70
	}
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    71
	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    72
	y += 10;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    73
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    74
	/* Design date - Life length */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    75
	SetDParam(0, ymd.year + 1920);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    76
	SetDParam(1, e->lifelength);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    77
	DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    78
	y += 10;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    79
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    80
	/* Reliability */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    81
	SetDParam(0, e->reliability * 100 >> 16);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    82
	DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    83
	y += 10;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    84
}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    85
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    86
/**
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    87
 * Draw the purchase info details of a train wagon at a given location.
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    88
 * @param x,y location where to draw the info
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    89
 * @param engine_number the engine of which to draw the info of
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    90
 */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    91
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    92
{
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
    93
	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
    94
	bool refittable = (_engine_info[engine_number].refit_mask != 0);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
    95
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    96
	/* Purchase cost */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    97
	SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    98
	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
    99
	y += 10;
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   100
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   101
	/* Wagon weight - (including cargo) */
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   102
	SetDParam(0, rvi->weight);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   103
	SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   104
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   105
	y += 10;
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   106
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   107
	/* Cargo type + capacity */
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   108
	SetDParam(0, _cargoc.names_long[rvi->cargo_type]);
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   109
	SetDParam(1, rvi->capacity);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   110
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   111
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   112
	y += 10;
2443
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   113
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   114
	/* Wagon speed limit, displayed if above zero */
2456
93041d70867b (svn r2982) Newgrf: Added patch option for wagon speed limits. This is enabled by default.
peter1138
parents: 2443
diff changeset
   115
	if (rvi->max_speed > 0 && _patches.wagon_speed_limits) {
2443
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   116
		SetDParam(0, rvi->max_speed * 10 >> 4);
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   117
		DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0);
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   118
		y += 10;
62ff46a3f530 (svn r2969) -Newgrf: Show a wagon's speed limit in purchase list.
peter1138
parents: 2436
diff changeset
   119
	}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   120
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   122
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
   123
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	Vehicle *v,*found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	if (!success)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	// find a locomotive in the depot.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	found = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	FOR_ALL_VEHICLES(v) {
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   132
		if (v->type == VEH_Train && IsFrontEngine(v) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
				v->tile == tile &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
				v->u.rail.track == 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
			if (found != NULL) // must be exactly one.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
			found = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	// if we found a loco,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	if (found != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
		found = GetLastVehicleInChain(found);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
		// put the new wagon at the end of the loco.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		DoCommandP(0, _new_wagon_id | (found->index<<16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
   146
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   150
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
   151
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2611
diff changeset
   152
	const Vehicle* v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   154
	if (!success) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   155
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   156
	v = GetVehicle(_new_train_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	if (tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
		RestoreVehicleOrders(v, _backup_orders_data);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	ShowTrainViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   164
void CcCloneTrain(bool success, uint tile, uint32 p1, uint32 p2)
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   165
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   166
	if (success) ShowTrainViewWindow(GetVehicle(_new_train_id));
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   167
}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   168
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   169
static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2518
diff changeset
   170
	EngineID* selected_id, RailType railtype, byte show_max, bool is_engine)
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   171
{
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   172
	EngineID i;
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   173
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   174
	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   175
		const Engine *e = GetEngine(i);
539
ccf9518e6cfd (svn r923) Forgot s/rail_vehinfo/RailVehInfo/
tron
parents: 538
diff changeset
   176
		const RailVehicleInfo *rvi = RailVehInfo(i);
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   177
2518
90e37afa8a3c (svn r3047) The parameters for the railtype check got flipped in the train build window (this caused no visible problem so far, therefore no Fix tag)
tron
parents: 2517
diff changeset
   178
		if (!IsCompatibleRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine ||
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   179
				!HASBIT(e->player_avail, _local_player))
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   180
			continue;
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   181
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   182
		if (*sel == 0)
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   183
			*selected_id = i;
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   184
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   185
		if (IS_INT_INSIDE(--*pos, -show_max, 0)) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   186
			DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10);
2570
c7c4d8438516 (svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents: 2562
diff changeset
   187
			DrawTrainEngine(*x + 29, *y + 6, i,
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   188
				SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   189
			*y += 14;
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   190
		}
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   191
		--*sel;
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   192
	}
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   193
}
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   194
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	switch(e->event) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	case WE_PAINT:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   199
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		if (w->window_number == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
			SETBIT(w->disabled_state, 5);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
			int count = 0;
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2518
diff changeset
   205
			RailType railtype = WP(w,buildtrain_d).railtype;
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   206
			EngineID i;
460
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 420
diff changeset
   207
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 420
diff changeset
   208
			for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1922
diff changeset
   209
				const Engine *e = GetEngine(i);
2518
90e37afa8a3c (svn r3047) The parameters for the railtype check got flipped in the train build window (this caused no visible problem so far, therefore no Fix tag)
tron
parents: 2517
diff changeset
   210
				if (IsCompatibleRail(e->railtype, railtype)
460
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 420
diff changeset
   211
				    && HASBIT(e->player_avail, _local_player))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
					count++;
460
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 420
diff changeset
   213
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
			SetVScrollCount(w, count);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   217
		SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
		DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   219
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		{
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2518
diff changeset
   221
			RailType railtype = WP(w,buildtrain_d).railtype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
			int sel = WP(w,buildtrain_d).sel_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
			int pos = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
			int x = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
			int y = 15;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   226
			EngineID selected_id = INVALID_ENGINE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
460
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 420
diff changeset
   228
			/* Ensure that custom engines which substituted wagons
524
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   229
			 * are sorted correctly.
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   230
			 * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   231
			 * engines to get more types.. Stays here until we have our own format
6ed367906581 (svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents: 517
diff changeset
   232
			 * then it is exit!!! */
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   233
			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   234
			engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			WP(w,buildtrain_d).sel_engine = selected_id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   238
			if (selected_id != INVALID_ENGINE) {
539
ccf9518e6cfd (svn r923) Forgot s/rail_vehinfo/RailVehInfo/
tron
parents: 538
diff changeset
   239
				const RailVehicleInfo *rvi = RailVehInfo(selected_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
				if (!(rvi->flags & RVI_WAGON)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
					/* it's an engine */
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   243
					DrawTrainEnginePurchaseInfo(2, w->widget[4].top + 1,selected_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
					/* it's a wagon */
1907
cebdef7a1c8a (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   246
					DrawTrainWagonPurchaseInfo(2, w->widget[4].top + 1, selected_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		switch(e->click.widget) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		case 2: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
			uint i = (e->click.pt.y - 14) / 14;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   256
			if (i < w->vscroll.cap) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
				WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		case 5: {
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   262
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   263
			if (sel_eng != INVALID_ENGINE)
540
fbed599dadbb (svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents: 539
diff changeset
   264
				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));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
		}	break;
968
9c47631d62dc (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
   266
		case 6: { /* rename */
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   267
			EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   268
			if (sel_eng != INVALID_ENGINE) {
968
9c47631d62dc (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
   269
				WP(w,buildtrain_d).rename_engine = sel_eng;
9c47631d62dc (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
   270
				ShowQueryString(GetCustomEngineName(sel_eng),
9c47631d62dc (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
   271
					STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number);
9c47631d62dc (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
   272
			}
9c47631d62dc (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
   273
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
		if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
			DeleteWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	case WE_ON_EDIT_TEXT: {
1820
9b6458526480 (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
   284
		if (e->edittext.str[0] != '\0') {
9b6458526480 (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
   285
			_cmd_text = e->edittext.str;
9b6458526480 (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
   286
			DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL,
9b6458526480 (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
   287
				CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
9b6458526480 (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
   288
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	} break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   290
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   291
	case WE_RESIZE: {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   292
		if (e->sizing.diff.y == 0)
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   293
			break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   294
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   295
		w->vscroll.cap += e->sizing.diff.y / 14;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   296
		w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   297
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   300
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
static const Widget _new_rail_vehicle_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   302
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,									STR_018B_CLOSE_WINDOW},
1017
608592d4d7a6 (svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents: 1006
diff changeset
   303
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   227,     0,    13, STR_JUST_STRING,					STR_018C_WINDOW_TITLE_DRAG_THIS},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
   304
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,										STR_8843_TRAIN_VEHICLE_SELECTION},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
   305
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, 0x0,											STR_0190_SCROLL_BAR_SCROLLS_LIST},
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   306
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   197, 0x0,											STR_NULL},
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   307
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   107,   198,   209, STR_881F_BUILD_VEHICLE,		STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   308
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   108,   215,   198,   209, STR_8820_RENAME,					STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   309
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   216,   227,   198,   209, 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
   310
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
static const WindowDesc _new_rail_vehicle_desc = {
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1907
diff changeset
   314
	-1, -1, 228, 210,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	WC_BUILD_VEHICLE,0,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   316
	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
   317
	_new_rail_vehicle_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	NewRailVehicleWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   321
static void ShowBuildTrainWindow(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	w = AllocateWindowDesc(&_new_rail_vehicle_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	w->window_number = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	w->vscroll.cap = 8;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   330
	w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   331
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   332
	w->resize.step_height = 14;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   333
	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
   334
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	if (tile != 0) {
1901
fb05044cf5c3 (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
   336
		w->caption_color = GetTileOwner(tile);
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2484
diff changeset
   337
		WP(w,buildtrain_d).railtype = GB(_m[tile].m3, 0, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
		w->caption_color = _local_player;
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2113
diff changeset
   340
		WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
2593
a9f7d3d70639 (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
   344
/**
a9f7d3d70639 (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
   345
 * Get the number of pixels for the given wagon length.
a9f7d3d70639 (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
   346
 * @param len Length measured in 1/8ths of a standard wagon.
a9f7d3d70639 (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
   347
 * @return Number of pixels across.
a9f7d3d70639 (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
   348
 */
a9f7d3d70639 (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
   349
static int WagonLengthToPixels(int len) {
a9f7d3d70639 (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
   350
	return (len * 29) / 8;
a9f7d3d70639 (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
   351
}
a9f7d3d70639 (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
   352
1790
4afb4b4e4278 (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
   353
static 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
   354
{
2593
a9f7d3d70639 (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
   355
	int dx = 0;
a9f7d3d70639 (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
   356
	count *= 8;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   357
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		if (--skip < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
			int image = GetTrainImage(v, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
			uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
2593
a9f7d3d70639 (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
   362
			int width = v->u.rail.cached_veh_length;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   363
2593
a9f7d3d70639 (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
   364
			if (dx + width <= count) {
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   365
				if (v->vehstatus & VS_CRASHED)
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   366
					ormod = PALETTE_CRASH;
2593
a9f7d3d70639 (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
   367
				DrawSprite(image | ormod, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   368
				if (v->index == selection)
2593
a9f7d3d70639 (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
   369
					DrawFrameRect(x - 1 + WagonLengthToPixels(dx), y - 1, x + WagonLengthToPixels(dx + width) - 1, y + 12, 15, FR_BORDERONLY);
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   370
			}
2593
a9f7d3d70639 (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
   371
			dx += width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
2593
a9f7d3d70639 (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
   374
		v = v->next;
a9f7d3d70639 (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
   375
	} while (dx < count && v != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
static void DrawTrainDepotWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   380
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	Vehicle *v, *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	int num,x,y,i, hnum;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   383
	Depot *depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
	tile = w->window_number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	/* setup disabled buttons */
1901
fb05044cf5c3 (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
   388
	w->disabled_state =
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   389
		IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8) | (1<<9));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
	/* determine amount of items for scroller */
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   392
	num = 0;
2593
a9f7d3d70639 (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
   393
	hnum = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		if (v->type == VEH_Train &&
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   396
			  (IsFrontEngine(v) || IsFreeWagon(v)) &&
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   397
				v->tile == tile &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
				v->u.rail.track == 0x80) {
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   399
			num++;
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   400
			// determine number of items in the X direction.
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   401
			if (IsFrontEngine(v)) {
2593
a9f7d3d70639 (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
   402
				hnum = max(hnum, v->u.rail.cached_total_length);
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   403
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	}
914
c3ad2a35b937 (svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents: 894
diff changeset
   406
c3ad2a35b937 (svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents: 894
diff changeset
   407
	/* Always have 1 empty row, so people can change the setting of the train */
c3ad2a35b937 (svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents: 894
diff changeset
   408
	num++;
c3ad2a35b937 (svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents: 894
diff changeset
   409
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	SetVScrollCount(w, num);
2593
a9f7d3d70639 (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
   411
	SetHScrollCount(w, (hnum + 7) / 8);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   412
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	/* locate the depot struct */
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   414
	depot = GetDepotByTile(tile);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   415
	assert(depot != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   417
	SetDParam(0, depot->town_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	x = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	y = 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	num = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	// draw all trains
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	FOR_ALL_VEHICLES(v) {
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   426
		if (v->type == VEH_Train && IsFrontEngine(v) &&
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   427
				v->tile == tile && v->u.rail.track == 0x80 &&
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   428
				--num < 0 && num >= -w->vscroll.cap) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   429
			DrawTrainImage(v, x+21, y, w->hscroll.cap, w->hscroll.pos, WP(w,traindepot_d).sel);
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 10
diff changeset
   430
			/* Draw the train number */
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   431
			SetDParam(0, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
			DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
   433
2593
a9f7d3d70639 (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
   434
			// Number of wagons relative to a standard length wagon (rounded up)
a9f7d3d70639 (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
   435
			SetDParam(0, (v->u.rail.cached_total_length + 7) / 8);
2113
f228b399da01 (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
   436
			DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0);	//Draw the counter
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
   437
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 10
diff changeset
   438
			/* Draw the pretty flag */
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   439
			DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + 15, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	// draw all remaining vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	FOR_ALL_VEHICLES(v) {
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   447
		if (v->type == VEH_Train && IsFreeWagon(v) &&
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1977
diff changeset
   448
				v->tile == tile && v->u.rail.track == 0x80 &&
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   449
				--num < 0 && num >= -w->vscroll.cap) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   450
			DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 0, WP(w,traindepot_d).sel);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
			DrawString(x, y+2, STR_8816, 0);
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1017
diff changeset
   452
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   453
			/*Draw the train counter */
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   454
			i = 0;
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   455
			u = v;
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   456
			do i++; while ( (u=u->next) != NULL);		//Determine length of train
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   457
			SetDParam(0, i);				//Set the counter
2113
f228b399da01 (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
   458
			DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0);	//Draw the counter
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
			y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
typedef struct GetDepotVehiclePtData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	Vehicle *head;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	Vehicle *wagon;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
} GetDepotVehiclePtData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   469
static int GetVehicleFromTrainDepotWndPt(const Window *w, int x, int y, GetDepotVehiclePtData *d)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	int row;
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   472
	int skip = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	x = x - 23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	row = (y - 14) / 14;
914
c3ad2a35b937 (svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents: 894
diff changeset
   478
	if ( (uint) row >= w->vscroll.cap)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		return 1; /* means err */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	row += w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	/* go through all the locomotives */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
		if (v->type == VEH_Train &&
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   486
				IsFrontEngine(v) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
				v->tile == w->window_number &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
				v->u.rail.track == 0x80 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
				--row < 0) {
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   490
					skip = w->hscroll.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
					goto found_it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   495
	x -= 29; /* free wagons don't have an initial loco. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
	/* and then the list of free wagons */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		if (v->type == VEH_Train &&
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   500
				IsFreeWagon(v) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
				v->tile == w->window_number &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
				v->u.rail.track == 0x80 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
				--row < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
					goto found_it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	d->head = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
	d->wagon = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	/* didn't find anything, get out */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   513
found_it:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	d->head = d->wagon = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	/* either pressed the flag or the number, but only when it's a loco */
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   517
	if (x < 0 && IsFrontEngine(v))
1922
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   518
		return (x >= -10) ? -2 : -1;
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   519
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   520
	// skip vehicles that are scrolled off the left side
797081e56d13 (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1908
diff changeset
   521
	while (skip--) v = v->next;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   522
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	/* find the vehicle in this row that was clicked */
2593
a9f7d3d70639 (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
   524
	while ((x -= WagonLengthToPixels(v->u.rail.cached_veh_length)) >= 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
		v = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		if (v == NULL) break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
   529
	// if an articulated part was selected, find its parent
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   530
	while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
   531
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   532
	d->wagon = v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   537
static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   541
	v = GetVehicle(sel);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   543
	if (v == wagon)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	if (wagon == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		if (head != NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
			wagon = GetLastVehicleInChain(head);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	} else  {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		wagon = GetPrevVehicleInChain(wagon);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
		if (wagon == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
	if (wagon == v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   558
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
static void TrainDepotClickTrain(Window *w, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
	GetDepotVehiclePtData gdvp;
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   564
	int mode;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp);
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   568
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   569
	// share / copy orders
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; }
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   571
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	v = gdvp.wagon;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	switch(mode) {
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   575
	case 0: { // start dragging of vehicle
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   576
		VehicleID sel = WP(w, traindepot_d).sel;
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   577
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   578
		if (sel != INVALID_VEHICLE) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
			TrainDepotMoveVehicle(v, sel, gdvp.head);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
		} else if (v != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
			WP(w,traindepot_d).sel = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
		break;
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
   587
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   589
	case -1: // show info window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
		ShowTrainViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
10
c35ab8426202 (svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents: 0
diff changeset
   593
	case -2: // click start/stop flag
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   599
/**
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   600
 * Clones a train
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   601
 * @param *v is the original vehicle to clone
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   602
 * @param *w is the window of the depot where the clone is build
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   603
 */
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   604
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   605
{
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   606
	if (v == NULL || v->type != VEH_Train) return;
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   607
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   608
	// for train vehicles: subtype 0 for locs and not zero for others
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   609
	if (!IsFrontEngine(v)) {
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   610
		v = GetFirstVehicleInChain(v);
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   611
		// Do nothing when clicking on a train in depot with no loc attached
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   612
		if (!IsFrontEngine(v)) return;
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   613
	}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   614
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   615
	DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain,
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   616
		CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   617
	);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   618
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   619
	ResetObjectToPlace();
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   620
}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   621
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   622
static void ClonePlaceObj(TileIndex tile, const Window* w)
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   623
{
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   624
	Vehicle* v = CheckMouseOverVehicle();
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   625
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   626
	if (v != NULL) HandleCloneVehClick(v, w);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   627
}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   628
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
static void TrainDepotWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	switch(e->event) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
		DrawTrainDepotWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
		switch(e->click.widget) {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   638
		case 8:
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   639
			ResetObjectToPlace();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
			ShowBuildTrainWindow(w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
			break;
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   642
		case 10:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   643
			ResetObjectToPlace();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
			ScrollMainWindowToTile(w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
			break;
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   646
		case 6:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
			TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
			break;
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   649
		case 9: /* clone button */
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   650
			InvalidateWidget(w, 9);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   651
			TOGGLEBIT(w->click_state, 9);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   652
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   653
			if (HASBIT(w->click_state, 9)) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   654
				_place_clicked_vehicle = NULL;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   655
				SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   656
			} else {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   657
				ResetObjectToPlace();
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   658
			}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   659
			break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   660
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   661
 		}
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   662
 	} break;
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   663
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   664
	case WE_PLACE_OBJ: {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   665
		ClonePlaceObj(e->place.tile, w);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   666
	} break;
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   667
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   668
	case WE_ABORT_PLACE_OBJ: {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   669
		CLRBIT(w->click_state, 9);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   670
		InvalidateWidget(w, 9);
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   671
	} break;
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   672
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   673
	// check if a vehicle in a depot was clicked..
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   674
	case WE_MOUSELOOP: {
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   675
		const Vehicle* v = _place_clicked_vehicle;
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   676
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   677
		// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   678
		if (v != NULL && HASBIT(w->click_state, 9)) {
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   679
			_place_clicked_vehicle = NULL;
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   680
			HandleCloneVehClick(v, w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   684
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	case WE_DESTROY:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
		DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	case WE_DRAGDROP: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		switch(e->click.widget) {
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   691
		case 4: case 5: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
			Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
			int sell_cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
			/* sell vehicle */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
			if (w->disabled_state & (1 << e->click.widget))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
			if (WP(w,traindepot_d).sel == INVALID_VEHICLE)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   702
			v = GetVehicle(WP(w,traindepot_d).sel);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   703
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
			HandleButtonClick(w, e->click.widget);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   709
			sell_cmd = (e->click.widget == 5 || _ctrl_pressed) ? 1 : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   711
			if (!IsFrontEngine(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
				DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
				_backup_orders_tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
				BackupVehicleOrders(v, _backup_orders_data);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
				if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
					_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
		}	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   721
		case 6: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
				GetDepotVehiclePtData gdvp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
				VehicleID sel = WP(w,traindepot_d).sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
				WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   728
				if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
						sel != INVALID_VEHICLE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
					if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
						TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   732
					} else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
						ShowTrainViewWindow(gdvp.head);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
					}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   735
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
		default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
		} break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   744
	case WE_RESIZE: {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   745
		/* Update the scroll + matrix */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   746
		w->vscroll.cap += e->sizing.diff.y / 14;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   747
		w->hscroll.cap += e->sizing.diff.x / 29;
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   748
		w->widget[6].unkA = (w->vscroll.cap << 8) + 1;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   749
	} break;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
static const Widget _train_depot_widgets[] = {
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 968
diff changeset
   754
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,								STR_018B_CLOSE_WINDOW},
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   755
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   348,     0,    13, STR_8800_TRAIN_DEPOT,		STR_018C_WINDOW_TITLE_DRAG_THIS},
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   756
{  WWT_STICKYBOX,     RESIZE_LR,    14,   349,   360,     0,    13, 0x0,										STR_STICKY_BUTTON},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   758
{      WWT_PANEL,    RESIZE_LRB,    14,   326,   348,    14,    13, 0x0,										STR_NULL},
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   759
{      WWT_PANEL,   RESIZE_LRTB,    14,   326,   348,    14,    54, 0x2A9,									STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE},
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   760
{      WWT_PANEL,   RESIZE_LRTB,    14,   326,   348,    55,   109, 0x2BF,									STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP},
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   761
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   762
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   325,    14,    97, 0x601,									STR_883F_TRAINS_CLICK_ON_TRAIN_FOR},
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   763
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   349,   360,    14,   109, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   764
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   116,   110,   121, STR_8815_NEW_VEHICLES,	STR_8840_BUILD_NEW_TRAIN_VEHICLE},
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   765
{WWT_NODISTXTBTN,     RESIZE_TB,    14,   117,   232,   110,   121, STR_CLONE_TRAIN,		STR_CLONE_TRAIN_DEPOT_INFO},
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   766
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   233,   348,   110,   121, STR_00E4_LOCATION,			STR_8842_CENTER_MAIN_VIEW_ON_TRAIN},
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   767
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   768
1658
bf518eb5d3b4 (svn r2162) - Fix: Tooltips of horizontal scrollbars were wrong; they now say left/right instead of up/down
Darkvater
parents: 1485
diff changeset
   769
{ WWT_HSCROLLBAR,    RESIZE_RTB,    14,     0,   325,    98,   109, 0x0,										STR_HSCROLL_BAR_SCROLLS_LIST},
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   770
{      WWT_PANEL,    RESIZE_RTB,    14,   349,   348,   110,   121, 0x0,										STR_NULL},
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   771
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   772
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   349,   360,   110,   121, 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
   773
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
static const WindowDesc _train_depot_desc = {
1002
ef08eb80686a (svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents: 982
diff changeset
   777
	-1, -1, 361, 122,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	WC_VEHICLE_DEPOT,0,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   779
	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
   780
	_train_depot_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	TrainDepotWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   785
void ShowTrainDepotWindow(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	w = AllocateWindowDescFront(&_train_depot_desc, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
	if (w) {
1901
fb05044cf5c3 (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
   791
		w->caption_color = GetTileOwner(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		w->vscroll.cap = 6;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   793
		w->hscroll.cap = 10;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   794
		w->resize.step_width = 29;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   795
		w->resize.step_height = 14;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
		WP(w,traindepot_d).sel = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
		_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
static void RailVehicleRefitWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
{
1802
448f187042d3 (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
   803
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	case WE_PAINT: {
1802
448f187042d3 (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
   805
		const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   807
		SetDParam(0, v->string_id);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   808
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		DrawWindowWidgets(w);
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
		DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
1802
448f187042d3 (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
   813
		/* TODO: Support for custom GRFSpecial-specified refitting! --pasky */
448f187042d3 (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
   814
		WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w, refit_d).sel);
382
c0b43541ed8e (svn r572) -newgrf: Support for custom (newGRF-yielded) refit masks for trains and aircrafts (pasky).
darkvater
parents: 338
diff changeset
   815
1802
448f187042d3 (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
   816
		if (WP(w,refit_d).cargo != CT_INVALID) {
448f187042d3 (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
   817
			int32 cost = DoCommandByTile(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_RAIL_VEHICLE);
448f187042d3 (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
   818
			if (!CmdFailed(cost)) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   819
				SetDParam(2, cost);
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   820
				SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   821
				SetDParam(1, _returned_refit_amount);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
				DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
		}
1802
448f187042d3 (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
   825
	}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	case WE_CLICK:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
		switch(e->click.widget) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		case 2: { /* listbox */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			int y = e->click.pt.y - 25;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
			if (y >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
				WP(w,refit_d).sel = y / 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		case 4: /* refit button */
1802
448f187042d3 (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
   837
			if (WP(w,refit_d).cargo != CT_INVALID) {
448f187042d3 (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
   838
				const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
					DeleteWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			break;
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
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
static const Widget _rail_vehicle_refit_widgets[] = {
2725
5c632bc5be28 (svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents: 2676
diff changeset
   850
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   851
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   239,     0,    13, STR_983B_REFIT,				STR_018C_WINDOW_TITLE_DRAG_THIS},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   852
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   239,    14,   135, 0x0,										STR_RAIL_SELECT_TYPE_OF_CARGO_FOR},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   853
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   239,   136,   157, 0x0,										STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   854
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   239,   158,   169, STR_RAIL_REFIT_VEHICLE,STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   855
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
static const WindowDesc _rail_vehicle_refit_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
	-1,-1, 240, 170,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	WC_VEHICLE_REFIT,WC_VEHICLE_VIEW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	_rail_vehicle_refit_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	RailVehicleRefitWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
static void ShowRailVehicleRefitWindow(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	_alloc_wnd_parent_num = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	w = AllocateWindowDesc(&_rail_vehicle_refit_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	w->window_number = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	WP(w,refit_d).sel = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
2275
cbaeb07740b1 (svn r2799) Make the only two non-const widget lists const
tron
parents: 2261
diff changeset
   877
static const Widget _train_view_widgets[] = {
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   878
{ WWT_CLOSEBOX,   RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5, STR_018B_CLOSE_WINDOW },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   879
{ WWT_CAPTION,    RESIZE_RIGHT, 14,  11, 237,   0,  13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   880
{ WWT_STICKYBOX,  RESIZE_LR,    14, 238, 249,   0,  13, 0x0,      STR_STICKY_BUTTON },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   881
{ WWT_PANEL,      RESIZE_RB,    14,   0, 231,  14, 121, 0x0,      STR_NULL },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   882
{ WWT_6,          RESIZE_RB,    14,   2, 229,  16, 119, 0x0,      STR_NULL },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   883
{ WWT_PUSHIMGBTN, RESIZE_RTB,   14,   0, 237, 122, 133, 0x0,      STR_8846_CURRENT_TRAIN_ACTION_CLICK },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   884
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  14,  31, 0x2AB,    STR_8848_CENTER_MAIN_VIEW_ON_TRAIN },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   885
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, 0x2AD,    STR_8849_SEND_TRAIN_TO_DEPOT },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   886
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  50,  67, 0x2B1,    STR_884A_FORCE_TRAIN_TO_PROCEED },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   887
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  68,  85, 0x2CB,    STR_884B_REVERSE_DIRECTION_OF_TRAIN },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   888
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  86, 103, 0x2B2,    STR_8847_SHOW_TRAIN_S_ORDERS },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   889
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249, 104, 121, 0x2B3,    STR_884C_SHOW_TRAIN_DETAILS },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   890
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  68,  85, 0x2B4,    STR_RAIL_REFIT_VEHICLE_TO_CARRY },
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   891
{ WWT_PUSHIMGBTN, RESIZE_LR,    14, 232, 249,  32,  49, SPR_CLONE_TRAIN,      STR_CLONE_TRAIN_INFO },
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   892
{ WWT_PANEL,      RESIZE_LRB,   14, 232, 249, 122, 121, 0x0,      STR_NULL },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   893
{ WWT_RESIZEBOX,  RESIZE_LRTB,  14, 238, 249, 122, 133, 0x0,      STR_NULL },
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
   894
{ WIDGETS_END }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   897
static void ShowTrainDetailsWindow(const Vehicle* v);
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   898
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
static void TrainViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
{
1802
448f187042d3 (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
   901
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	case WE_PAINT: {
1802
448f187042d3 (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
   903
		const Vehicle *v, *u;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
		StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   906
		v = GetVehicle(w->window_number);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   907
2867
66a9c4e27e34 (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
   908
		if (v->owner != _local_player) {
66a9c4e27e34 (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
   909
			w->disabled_state = 0x3380;
66a9c4e27e34 (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
   910
		} else {
66a9c4e27e34 (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
   911
			w->disabled_state = 0;
1387
eff794048d92 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   912
2867
66a9c4e27e34 (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
   913
			SETBIT(w->disabled_state, 12);
66a9c4e27e34 (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
   914
66a9c4e27e34 (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
   915
			/* See if any vehicle can be refitted */
66a9c4e27e34 (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
   916
			for (u = v; u != NULL; u = u->next) {
66a9c4e27e34 (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
   917
				if (_engine_info[u->engine_type].refit_mask != 0 ||
66a9c4e27e34 (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
   918
						(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
66a9c4e27e34 (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
   919
					CLRBIT(w->disabled_state, 12);
66a9c4e27e34 (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
   920
					/* We have a refittable carriage, bail out */
66a9c4e27e34 (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
   921
					break;
66a9c4e27e34 (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
   922
				}
1387
eff794048d92 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   923
			}
eff794048d92 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   924
		}
eff794048d92 (svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents: 1330
diff changeset
   925
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
		/* draw widgets & caption */
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   927
		SetDParam(0, v->string_id);
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2252
diff changeset
   928
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
		if (v->u.rail.crash_anim_pos != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
			str = STR_8863_CRASHED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		} else if (v->breakdown_ctr == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
			str = STR_885C_BROKEN_DOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		} else if (v->vehstatus & VS_STOPPED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
			if (v->u.rail.last_speed == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
				str = STR_8861_STOPPED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
			} else {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   939
				SetDParam(0, v->u.rail.last_speed * 10 >> 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
				str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
		} else {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   943
			switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
			case OT_GOTO_STATION: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   946
				SetDParam(0, v->current_order.station);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   947
				SetDParam(1, v->u.rail.last_speed * 10 >> 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
			case OT_GOTO_DEPOT: {
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   951
				Depot *dep = GetDepot(v->current_order.station);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   952
				SetDParam(0, dep->town_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
				str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   954
				SetDParam(1, v->u.rail.last_speed * 10 >> 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
			case OT_LOADING:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
			case OT_LEAVESTATION:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
				str = STR_882F_LOADING_UNLOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
395
4c990f33dab7 (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
   962
			case OT_GOTO_WAYPOINT: {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   963
				SetDParam(0, v->current_order.station);
395
4c990f33dab7 (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
   964
				str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   965
				SetDParam(1, v->u.rail.last_speed * 10 >> 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   968
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
				if (v->num_orders == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
					str = STR_NO_ORDERS + _patches.vehicle_speed;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
   972
					SetDParam(0, v->u.rail.last_speed * 10 >> 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
				} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
					str = STR_EMPTY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
				break;
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
2103
9266bb2ac29d (svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents: 2084
diff changeset
   979
		/* draw the flag plus orders */
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   980
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
2113
f228b399da01 (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
   981
		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
   982
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	}	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
		int wid = e->click.widget;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
   987
		Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		switch(wid) {
755
823358e83abf (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
   990
		case 5: /* start/stop train */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   991
			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
   992
			break;
755
823358e83abf (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
   993
		case 6:	/* center main view */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
			ScrollMainWindowTo(v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
			break;
755
823358e83abf (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
   996
		case 7:	/* goto depot */
601
952c0295f79a (svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents: 588
diff changeset
   997
			/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
952c0295f79a (svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents: 588
diff changeset
   998
			DoCommandP(v->tile, v->index, 0, NULL, CMD_TRAIN_GOTO_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
   999
			break;
755
823358e83abf (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
  1000
		case 8: /* force proceed */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1001
			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
  1002
			break;
755
823358e83abf (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
  1003
		case 9: /* reverse direction */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1004
			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
  1005
			break;
755
823358e83abf (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
  1006
		case 10: /* show train orders */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
			ShowOrdersWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			break;
755
823358e83abf (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
  1009
		case 11: /* show train details */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
			ShowTrainDetailsWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
			break;
755
823358e83abf (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
  1012
		case 12:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
			ShowRailVehicleRefitWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
			break;
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1015
		case 13:
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1016
			DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1017
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1021
	case WE_RESIZE:
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1022
		w->viewport->width  += e->sizing.diff.x;
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1023
		w->viewport->height += e->sizing.diff.y;
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1024
		w->viewport->virtual_width  += e->sizing.diff.x;
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1025
		w->viewport->virtual_height += e->sizing.diff.y;
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1026
		break;
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1027
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
	case WE_DESTROY:
338
04ad3e897bf8 (svn r514) -Fix: [1053397] Refit Train Window Stays Open
tron
parents: 243
diff changeset
  1029
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
	case WE_MOUSELOOP: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
		Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
		uint32 h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1038
		v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		assert(v->type == VEH_Train);
2244
e6b5ef68406d (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
  1040
		h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9)| (1 << 7) : (1 << 12) | (1 << 13);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
		if (h != w->hidden_state) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
			w->hidden_state = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
static const WindowDesc _train_view_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	-1,-1, 250, 134,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	WC_VEHICLE_VIEW,0,
1485
a2f36708c260 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1402
diff changeset
  1054
	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
  1055
	_train_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
	TrainViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
  1059
void ShowTrainViewWindow(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
{
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
  1061
	Window* w = AllocateWindowDescFront(&_train_view_desc,v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
  1063
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
		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
  1066
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
1790
4afb4b4e4278 (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
  1069
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
  1070
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	if (v->cargo_cap != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
		num = v->cargo_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
		str = STR_8812_EMPTY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
		if (num != 0) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1078
			SetDParam(0, v->cargo_type);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1079
			SetDParam(1, num);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1080
			SetDParam(2, v->cargo_source);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
			str = STR_8813_FROM;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		DrawString(x, y, str, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
1790
4afb4b4e4278 (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
  1087
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
  1088
{
540
fbed599dadbb (svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents: 539
diff changeset
  1089
	const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	if (!(rvi->flags & RVI_WAGON)) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1092
		SetDParam(0, GetCustomEngineName(v->engine_type));
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1093
		SetDParam(1, v->build_year + 1920);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1094
		SetDParam(2, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
		DrawString(x, y, STR_882C_BUILT_VALUE, 0x10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	} else {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1097
		SetDParam(0, GetCustomEngineName(v->engine_type));
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1098
		SetDParam(1, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		DrawString(x, y, STR_882D_VALUE, 0x10);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1100
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
1790
4afb4b4e4278 (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
  1103
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
  1104
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	if (v->cargo_cap != 0) {
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
  1106
		SetDParam(0, _cargoc.names_long[v->cargo_type]);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1107
		SetDParam(1, v->cargo_cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
		DrawString(x, y, STR_013F_CAPACITY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
1790
4afb4b4e4278 (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
  1112
typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	TrainDetailsCargoTab,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
	TrainDetailsInfoTab,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	TrainDetailsCapacityTab,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
static void DrawTrainDetailsWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
{
1790
4afb4b4e4278 (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
  1122
	const Vehicle *v, *u;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	uint16 tot_cargo[NUM_CARGO][2];	// count total cargo ([0]-actual cargo, [1]-total cargo)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	int i,num,x,y,sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
	byte det_tab = WP(w, traindetails_d).tab;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	/* Count number of vehicles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	// det_tab == 3 <-- Total Cargo tab
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	if (det_tab == 3)	// reset tot_cargo array to 0 values
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
		memset(tot_cargo, 0, sizeof(tot_cargo));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1133
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1134
	u = v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
		if (det_tab != 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
			num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
		else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
			tot_cargo[u->cargo_type][0] += u->cargo_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
			tot_cargo[u->cargo_type][1] += u->cargo_cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
		}
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1142
	} while ((u = GetNextVehicle(u)) != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	/*	set scroll-amount seperately from counting, as to not
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
			compute num double for more carriages of the same type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	if (det_tab == 3) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
		for (i = 0; i != NUM_CARGO; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
			if (tot_cargo[i][1] > 0)	// only count carriages that the train has
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
		num++;	// needs one more because first line is description string
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	SetVScrollCount(w, num);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	w->disabled_state = 1 << (det_tab + 9);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	if (v->owner != _local_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
		w->disabled_state |= (1 << 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
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
  1161
	if (!_patches.servint_trains) // disable service-scroller when interval is set to disabled
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
  1162
		w->disabled_state |= (1 << 6) | (1 << 7);
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
  1163
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1164
	SetDParam(0, v->string_id);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1165
	SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	DrawWindowWidgets(w);
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
	num = v->age / 366;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1169
	SetDParam(1, num);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1170
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	x = 2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1172
2252
37e3ca7014e0 (svn r2772) Simplify the age notice in the vehicle details window
tron
parents: 2244
diff changeset
  1173
	SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1174
	SetDParam(2, v->max_age / 366);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1175
	SetDParam(3, GetTrainRunningCost(v) >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	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
  1177
1905
f43d9e821deb (svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents: 1901
diff changeset
  1178
	SetDParam(2, v->u.rail.cached_max_speed * 10 >> 4);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1179
	SetDParam(1, v->u.rail.cached_power);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1180
	SetDParam(0, v->u.rail.cached_weight);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_MAX_SPEED, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1183
	SetDParam(0, v->profit_this_year);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1184
	SetDParam(1, v->profit_last_year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	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
  1186
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1187
	SetDParam(0, 100 * (v->reliability>>8) >> 8);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1188
	SetDParam(1, v->breakdowns_since_last_service);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1191
	SetDParam(0, v->service_interval);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1192
	SetDParam(1, v->date_of_last_service);
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
  1193
	DrawString(x + 11, 141, _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
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	y = 57;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	sel = w->vscroll.pos;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1197
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	// draw the first 3 details tabs
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
	if (det_tab != 3) {
2822
ff15d6f947ed (svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents: 2819
diff changeset
  1200
		x = 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
		for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
			if (--sel < 0 && sel >= -6) {
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1203
				int dx = 0;
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1204
				u = v;
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1205
				do {
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1206
					DrawTrainImage(u, x + WagonLengthToPixels(dx), y, 1, 0, INVALID_VEHICLE);
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1207
					dx += u->u.rail.cached_veh_length;
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1208
					u = u->next;
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
  1209
				} while (u != NULL && IsArticulatedPart(u));
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1210
				_train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + WagonLengthToPixels(dx) + 2, y + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
				y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
			}
2602
f0e2dcce3695 (svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents: 2593
diff changeset
  1213
			if ((v = GetNextVehicle(v)) == NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	else {	// draw total cargo tab
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
		i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
		DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
			if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
				y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
				// STR_013F_TOTAL_CAPACITY			:{LTBLUE}- {CARGO} ({SHORTCARGO})
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1224
				SetDParam(0, i);								// {CARGO} #1
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1225
				SetDParam(1, tot_cargo[i][0]);	// {CARGO} #2
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1226
				SetDParam(2, i);								// {SHORTCARGO} #1
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1227
				SetDParam(3, tot_cargo[i][1]);	// {SHORTCARGO} #2
2822
ff15d6f947ed (svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents: 2819
diff changeset
  1228
				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
  1229
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
		} while (++i != NUM_CARGO);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
static void TrainDetailsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
{
1790
4afb4b4e4278 (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
  1236
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
		DrawTrainDetailsWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
		int mod;
1790
4afb4b4e4278 (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
  1242
		const Vehicle *v;
4afb4b4e4278 (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
  1243
		switch (e->click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
		case 2: /* name train */
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1245
			v = GetVehicle(w->window_number);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 524
diff changeset
  1246
			SetDParam(0, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
		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
  1250
			mod = _ctrl_pressed? 5 : 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
			goto do_change_service_int;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
		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
  1254
			mod = _ctrl_pressed? -5 : -10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
do_change_service_int:
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1256
			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
  1257
1790
4afb4b4e4278 (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
  1258
			mod = GetServiceIntervalClamped(mod + v->service_interval);
4afb4b4e4278 (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
  1259
			if (mod == v->service_interval) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1260
2819
710436dd4288 (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
  1261
			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
  1262
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
		/* details buttons*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
		case 9:		// Cargo
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		case 10:	// Information
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
		case 11:	// Capacities
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
		case 12:	// Total cargo
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
			CLRBIT(w->disabled_state, 9);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
			CLRBIT(w->disabled_state, 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
			CLRBIT(w->disabled_state, 11);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
			CLRBIT(w->disabled_state, 12);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
			SETBIT(w->disabled_state, e->click.widget);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
			WP(w,traindetails_d).tab = e->click.widget - 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
		if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
			DeleteWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2520
diff changeset
  1284
	case WE_ON_EDIT_TEXT:
1820
9b6458526480 (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
  1285
		if (e->edittext.str[0] != '\0') {
9b6458526480 (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
  1286
			_cmd_text = e->edittext.str;
9b6458526480 (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
  1287
			DoCommandP(0, w->window_number, 0, NULL,
9b6458526480 (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
  1288
				CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
9b6458526480 (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
  1289
		}
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2520
diff changeset
  1290
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
static const Widget _train_details_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1295
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,				STR_018B_CLOSE_WINDOW},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1296
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   329,     0,    13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1297
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   330,   369,     0,    13, STR_01AA_NAME,		STR_8867_NAME_TRAIN},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1298
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   369,    14,    55, 0x0,							STR_NULL},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1299
{     WWT_MATRIX,   RESIZE_NONE,    14,     0,   357,    56,   139, 0x601,						STR_NULL},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1300
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   358,   369,    56,   139, 0x0,							STR_0190_SCROLL_BAR_SCROLLS_LIST},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1301
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   140,   145, STR_0188,				STR_884D_INCREASE_SERVICING_INTERVAL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1302
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   146,   151, STR_0189,				STR_884E_DECREASE_SERVICING_INTERVAL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1303
{      WWT_PANEL,   RESIZE_NONE,    14,    11,   369,   140,   151, 0x0,							STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1304
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    92,   152,   163, STR_013C_CARGO,	STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1305
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    93,   184,   152,   163, STR_013D_INFORMATION,	STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1306
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   185,   277,   152,   163, STR_013E_CAPACITIES,		STR_8851_SHOW_CAPACITIES_OF_EACH},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1307
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   278,   369,   152,   163, STR_013E_TOTAL_CARGO,	STR_8852_SHOW_TOTAL_CARGO},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
  1308
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
static const WindowDesc _train_details_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	-1,-1, 370, 164,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
	WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	_train_details_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
	TrainDetailsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
2561
c78c3d248897 (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
  1321
static void ShowTrainDetailsWindow(const Vehicle* v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	VehicleID veh = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1329
	_alloc_wnd_parent_num = veh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
	w = AllocateWindowDesc(&_train_details_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
	w->window_number = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
	w->vscroll.cap = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
	WP(w,traindetails_d).tab = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1338
static const Widget _player_trains_widgets[] = {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1339
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1340
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1341
{  WWT_STICKYBOX,     RESIZE_LR,    14,   313,   324,     0,    13, 0x0,										STR_STICKY_BUTTON},
2806
0d747ab407a3 (svn r3354) Fix a typo, which survived for about 3000 revisions: s/SRT_SORT_BY/STR_SORT_BY/ (noticed by chu)
tron
parents: 2803
diff changeset
  1342
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,						STR_SORT_ORDER_TIP},
2803
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1343
{      WWT_PANEL,   RESIZE_NONE,    14,    81,   235,    14,    25, 0x0,										STR_SORT_CRITERIA_TIP},
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1344
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   236,   247,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1345
{      WWT_PANEL,  RESIZE_RIGHT,    14,   248,   324,    14,    25, 0x0,										STR_NULL},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1346
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   312,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1347
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   313,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1348
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   156,   208,   219, STR_8815_NEW_VEHICLES,	STR_883E_BUILD_NEW_TRAINS_REQUIRES},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1349
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   157,   312,   208,   219, STR_REPLACE_VEHICLES,    STR_REPLACE_HELP},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1350
{      WWT_PANEL,    RESIZE_RTB,    14,   313,   312,   208,   219, 0x0,										STR_NULL},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1351
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   313,   324,   208,   219, 0x0,										STR_RESIZE_BUTTON},
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1352
{   WIDGETS_END},
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1353
};
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1354
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1355
static const Widget _other_player_trains_widgets[] = {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1356
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1357
{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   312,     0,    13, STR_881B_TRAINS,				STR_018C_WINDOW_TITLE_DRAG_THIS},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1358
{  WWT_STICKYBOX,     RESIZE_LR,    14,   313,   324,     0,    13, 0x0,										STR_STICKY_BUTTON},
2806
0d747ab407a3 (svn r3354) Fix a typo, which survived for about 3000 revisions: s/SRT_SORT_BY/STR_SORT_BY/ (noticed by chu)
tron
parents: 2803
diff changeset
  1359
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,						STR_SORT_ORDER_TIP},
2803
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1360
{      WWT_PANEL,   RESIZE_NONE,    14,    81,   235,    14,    25, 0x0,										STR_SORT_CRITERIA_TIP},
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1361
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   236,   247,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
926cc62f35a7 (svn r3351) Make sort criteria selection widgets in player train list consistent with those widgets in other vehicle type lists. (Stops "Total capacity per cargo type" overflowing)
peter1138
parents: 2725
diff changeset
  1362
{      WWT_PANEL,  RESIZE_RIGHT,    14,   248,   324,    14,    25, 0x0,										STR_NULL},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1363
{     WWT_MATRIX,     RESIZE_RB,    14,     0,   312,    26,   207, 0x701,									STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1364
{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   313,   324,    26,   207, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1365
{      WWT_PANEL,    RESIZE_RTB,    14,     0,   312,   208,   219, 0x0,										STR_NULL},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 886
diff changeset
  1366
{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   313,   324,   208,   219, 0x0,										STR_RESIZE_BUTTON},
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1367
{   WIDGETS_END},
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1368
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
{
2466
2774132ebb9a (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2456
diff changeset
  1372
	StationID station = GB(w->window_number, 16, 16);
2774132ebb9a (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2456
diff changeset
  1373
	PlayerID owner = GB(w->window_number, 0, 8);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1374
	vehiclelist_d *vl = &WP(w, vehiclelist_d);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1375
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
	switch(e->event) {
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1377
	case WE_PAINT: {
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1378
		int x = 2;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1379
		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1380
		int max;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1381
		int i;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
  1382
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1383
		BuildVehicleList(vl, VEH_Train, owner, station);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1384
		SortVehicleList(vl);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1385
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1386
		SetVScrollCount(w, vl->list_length);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1387
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1388
		// disable 'Sort By' tooltip on Unsorted sorting criteria
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1389
		if (vl->sort_type == SORT_BY_UNSORTED)
757
a3510cb57cfc (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1390
			w->disabled_state |= (1 << 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1391
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		/* draw the widgets */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
		{
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1938
diff changeset
  1394
			const Player *p = GetPlayer(owner);
2466
2774132ebb9a (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2456
diff changeset
  1395
			if (station == INVALID_STATION) {
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1396
				/* Company Name -- (###) Trains */
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1397
				SetDParam(0, p->name_1);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1398
				SetDParam(1, p->name_2);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1399
				SetDParam(2, w->vscroll.count);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1400
				w->widget[1].unkA = STR_881B_TRAINS;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1401
			} else {
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1402
				/* Station Name -- (###) Trains */
1294
bc831562148e (svn r1798) GetFoo(i)->index is per definition i, so replace the former with the latter
tron
parents: 1246
diff changeset
  1403
				SetDParam(0, station);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1404
				SetDParam(1, w->vscroll.count);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1405
				w->widget[1].unkA = STR_SCHEDULED_TRAINS;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1406
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
			DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
		}
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
  1409
		/* draw sorting criteria string */
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1410
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1411
		/* draw arrow pointing up/down for ascending/descending sorting */
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2275
diff changeset
  1412
		DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1413
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1414
		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1415
		for (i = w->vscroll.pos; i < max; ++i) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1416
			Vehicle *v = GetVehicle(vl->sort_list[i].index);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1417
			StringID str;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1418
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1419
			assert(v->type == VEH_Train && v->owner == owner);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1420
2570
c7c4d8438516 (svn r3107) -NewGRF: Move train y-position offset adjustment to remove code duplication, and make it apply only to vehicles with a custom image.
peter1138
parents: 2562
diff changeset
  1421
			DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1422
			DrawVehicleProfitButton(v, x, y + 13);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1423
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1424
			SetDParam(0, v->unitnumber);
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1323
diff changeset
  1425
			if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN))
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1426
				str = STR_021F;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1427
			else
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1428
				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1429
			DrawString(x, y + 2, str, 0);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1430
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1431
			SetDParam(0, v->profit_this_year);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1432
			SetDParam(1, v->profit_last_year);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1433
			DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1434
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1435
			if (v->string_id != STR_SV_TRAIN_NAME) {
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1436
				SetDParam(0, v->string_id);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1437
				DrawString(x + 21, y, STR_01AB, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
			}
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1439
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1440
			y += PLY_WND_PRC__SIZE_OF_ROW_SMALL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
		}
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1442
		break;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1443
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	case WE_CLICK: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
		switch(e->click.widget) {
757
a3510cb57cfc (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1447
		case 3: /* Flip sorting method ascending/descending */
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1448
			vl->flags ^= VL_DESC;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1449
			vl->flags |= VL_RESORT;
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1179
diff changeset
  1450
			_sorting.train.order = !!(vl->flags & VL_DESC);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1451
			SetWindowDirty(w);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1452
			break;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1453
757
a3510cb57cfc (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1454
		case 4: case 5:/* Select sorting criteria dropdown menu */
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1455
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1456
			return;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1457
757
a3510cb57cfc (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1458
		case 7: { /* Matrix to show vehicles */
174
bd79fb899824 (svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
darkvater
parents: 168
diff changeset
  1459
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1460
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1461
			if (id_v >= w->vscroll.cap) return; // click out of bounds
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1463
			id_v += w->vscroll.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1465
			{
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1466
				Vehicle *v;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1467
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1468
				if (id_v >= vl->list_length) return; // click out of list bound
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1469
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 914
diff changeset
  1470
				v = GetVehicle(vl->sort_list[id_v].index);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1471
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
  1472
				assert(v->type == VEH_Train && IsFrontEngine(v) && v->owner == owner);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1473
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1474
				ShowTrainViewWindow(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
757
a3510cb57cfc (svn r1213) -Feature: Stickified vehicle lists
darkvater
parents: 755
diff changeset
  1478
		case 9: { /* Build new Vehicle */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1479
			TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1481
			if (!IsWindowOfPrototype(w, _player_trains_widgets))
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1482
				break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1483
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
			tile = _last_built_train_depot_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
			do {
1906
f5ae1d8ad052 (svn r2412) - Fix: [ 1214948 ] building vehicles without depot crashes game. (Chris Huebsch)
hackykid
parents: 1905
diff changeset
  1486
				if (IsTileDepotType(tile, TRANSPORT_RAIL) && IsTileOwner(tile, _local_player)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
					ShowTrainDepotWindow(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
					ShowBuildTrainWindow(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1491
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
				tile = TILE_MASK(tile + 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
			} while(tile != _last_built_train_depot_tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1494
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
			ShowBuildTrainWindow(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
		} break;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1497
		case 10: {
886
4442d7859ea7 (svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents: 878
diff changeset
  1498
			if (!IsWindowOfPrototype(w, _player_trains_widgets))
4442d7859ea7 (svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents: 878
diff changeset
  1499
				break;
4442d7859ea7 (svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents: 878
diff changeset
  1500
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1501
			ShowReplaceVehicleWindow(VEH_Train);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1502
			break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1503
 		}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
  1504
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	}	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1508
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1509
		if (vl->sort_type != e->dropdown.index) {
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1510
			// value has changed -> resort
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1511
			vl->flags |= VL_RESORT;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1512
			vl->sort_type = e->dropdown.index;
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1179
diff changeset
  1513
			_sorting.train.criteria = vl->sort_type;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1514
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1515
			// enable 'Sort By' if a sorter criteria is chosen
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1516
			if (vl->sort_type != SORT_BY_UNSORTED)
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1179
diff changeset
  1517
				CLRBIT(w->disabled_state, 3);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1518
		}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1519
		SetWindowDirty(w);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1520
		break;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1521
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1522
	case WE_CREATE: /* set up resort timer */
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1523
		vl->sort_list = NULL;
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1179
diff changeset
  1524
		vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1179
diff changeset
  1525
		vl->sort_type = _sorting.train.criteria;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1526
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1527
		break;
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1528
767
13c481dee3fc (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1529
	case WE_DESTROY:
13c481dee3fc (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1530
		free(vl->sort_list);
13c481dee3fc (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1531
		break;
13c481dee3fc (svn r1232) Plug memory leak
tron
parents: 757
diff changeset
  1532
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1533
	case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1534
		if (--vl->resort_timer == 0) {
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1535
			DEBUG(misc, 1) ("Periodic resort trains list player %d station %d",
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1536
				owner, station);
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1537
			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1538
			vl->flags |= VL_RESORT;
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1539
			SetWindowDirty(w);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1540
		}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1541
		break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1542
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1543
	case WE_RESIZE:
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1544
		/* Update the scroll + matrix */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1545
		w->hscroll.cap += e->sizing.diff.x / 29;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1546
		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1547
		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1548
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
static const WindowDesc _player_trains_desc = {
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1553
	-1, -1, 325, 220,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	WC_TRAINS_LIST,0,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1555
	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
  1556
	_player_trains_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
	PlayerTrainsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
static const WindowDesc _other_player_trains_desc = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1561
	-1, -1, 325, 220,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
	WC_TRAINS_LIST,0,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1563
	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
  1564
	_other_player_trains_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
	PlayerTrainsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
2466
2774132ebb9a (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2456
diff changeset
  1568
void ShowPlayerTrains(PlayerID player, StationID station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1572
	if (player == _local_player) {
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1573
		w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1574
	} else {
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 573
diff changeset
  1575
		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
	if (w) {
1402
05f6d79373ee (svn r1906) - Fix: [ 1117327 ] Assertion error on kick. When a company is cleaned all its windows need to be closed. For global vehicle lists, the no-staiton index of -1 was not taken into account
Darkvater
parents: 1387
diff changeset
  1578
		w->caption_color = player;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1579
		w->hscroll.cap = 10;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 156
diff changeset
  1580
		w->vscroll.cap = 7; // maximum number of vehicles shown
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1581
		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1582
		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1583
		w->resize.step_width = 29;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
  1584
		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
}