author | tron |
Sun, 17 Jul 2005 20:14:58 +0000 | |
changeset 2116 | 23031555ff54 |
parent 2113 | be2f07df0dfa |
child 2147 | eb6ba42fd216 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
2 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
3 |
#include "debug.h" |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
4 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
460
diff
changeset
|
5 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
601
diff
changeset
|
6 |
#include "map.h" |
0 | 7 |
#include "window.h" |
8 |
#include "gui.h" |
|
9 |
#include "gfx.h" |
|
10 |
#include "vehicle.h" |
|
11 |
#include "viewport.h" |
|
12 |
#include "station.h" |
|
13 |
#include "command.h" |
|
14 |
#include "player.h" |
|
15 |
#include "engine.h" |
|
588 | 16 |
#include "vehicle_gui.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
17 |
#include "depot.h" |
420
d4aa4a1df3c6
(svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents:
395
diff
changeset
|
18 |
|
d4aa4a1df3c6
(svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents:
395
diff
changeset
|
19 |
int _traininfo_vehicle_pitch = 0; |
d4aa4a1df3c6
(svn r617) -newgrf: Support for parameter 0x8E (train Y-pitch in info windows) both setting and testing. This should fix displaced wagons in DBSetXL as reported by DarkVater. (pasky)
darkvater
parents:
395
diff
changeset
|
20 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
21 |
/** |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
22 |
* Draw the purchase info details of train engine at a given location. |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
23 |
* @param x,y location where to draw the info |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
24 |
* @param engine_number the engine of which to draw the info of |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
25 |
*/ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
26 |
void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number) |
842 | 27 |
{ |
28 |
const RailVehicleInfo *rvi = RailVehInfo(engine_number); |
|
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
29 |
const Engine* e = GetEngine(engine_number); |
842 | 30 |
int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); |
31 |
YearMonthDay ymd; |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
32 |
ConvertDayToYMD(&ymd, e->intro_date); |
842 | 33 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
34 |
/* Purchase Cost - Engine weight */ |
842 | 35 |
SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5); |
36 |
SetDParam(1, rvi->weight << multihead); |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
37 |
DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
38 |
y += 10; |
842 | 39 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
40 |
/* Max speed - Engine power */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
41 |
SetDParam(0, rvi->max_speed * 10 >> 4); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
42 |
SetDParam(1, rvi->power << multihead); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
43 |
DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
44 |
y += 10; |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
45 |
|
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
46 |
/* Running cost */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
47 |
SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8) << multihead); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
48 |
DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
49 |
y += 10; |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
50 |
|
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
51 |
/* Powered wagons power - Powered wagons extra weight */ |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
52 |
if (rvi->pow_wag_power != 0) { |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
53 |
SetDParam(0, rvi->pow_wag_power); |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
54 |
SetDParam(1, rvi->pow_wag_weight); |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
55 |
DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0); |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
56 |
y += 10; |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
57 |
}; |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
58 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
59 |
/* Cargo type + capacity, or N/A */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
60 |
SetDParam(0, STR_8838_N_A); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
61 |
SetDParam(2, STR_EMPTY); |
842 | 62 |
if (rvi->capacity != 0) { |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2049
diff
changeset
|
63 |
SetDParam(0, _cargoc.names_long[rvi->cargo_type]); |
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
64 |
SetDParam(1, rvi->capacity << multihead); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
65 |
SetDParam(2, STR_9842_REFITTABLE); |
842 | 66 |
} |
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
67 |
DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
68 |
y += 10; |
842 | 69 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
70 |
/* Design date - Life length */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
71 |
SetDParam(0, ymd.year + 1920); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
72 |
SetDParam(1, e->lifelength); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
73 |
DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
74 |
y += 10; |
842 | 75 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
76 |
/* Reliability */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
77 |
SetDParam(0, e->reliability * 100 >> 16); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
78 |
DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
79 |
y += 10; |
842 | 80 |
} |
81 |
||
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
82 |
/** |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
83 |
* Draw the purchase info details of a train wagon at a given location. |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
84 |
* @param x,y location where to draw the info |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
85 |
* @param engine_number the engine of which to draw the info of |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
86 |
*/ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
87 |
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number) |
842 | 88 |
{ |
89 |
const RailVehicleInfo *rvi = RailVehInfo(engine_number); |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
90 |
bool refittable = (_engine_refit_masks[engine_number] != 0); |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
91 |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
92 |
/* Purchase cost */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
93 |
SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
94 |
DrawString(x, y, STR_PURCHASE_INFO_COST, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
95 |
y += 10; |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
96 |
|
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
97 |
/* Wagon weight - (including cargo) */ |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
98 |
SetDParam(0, rvi->weight); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
99 |
SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
100 |
DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
101 |
y += 10; |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
102 |
|
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
103 |
/* Cargo type + capacity */ |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2049
diff
changeset
|
104 |
SetDParam(0, _cargoc.names_long[rvi->cargo_type]); |
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
105 |
SetDParam(1, rvi->capacity); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
106 |
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
107 |
DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); |
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
108 |
y += 10; |
842 | 109 |
} |
0 | 110 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
111 |
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 112 |
{ |
113 |
Vehicle *v,*found; |
|
114 |
||
115 |
if (!success) |
|
116 |
return; |
|
117 |
||
118 |
// find a locomotive in the depot. |
|
119 |
found = NULL; |
|
120 |
FOR_ALL_VEHICLES(v) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
121 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine && |
0 | 122 |
v->tile == tile && |
123 |
v->u.rail.track == 0x80) { |
|
124 |
if (found != NULL) // must be exactly one. |
|
125 |
return; |
|
126 |
found = v; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
// if we found a loco, |
|
131 |
if (found != NULL) { |
|
132 |
found = GetLastVehicleInChain(found); |
|
133 |
// put the new wagon at the end of the loco. |
|
134 |
DoCommandP(0, _new_wagon_id | (found->index<<16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); |
|
588 | 135 |
RebuildVehicleLists(); |
0 | 136 |
} |
137 |
} |
|
138 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
139 |
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 140 |
{ |
141 |
Vehicle *v; |
|
142 |
||
143 |
if (!success) |
|
144 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
145 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
146 |
v = GetVehicle(_new_train_id); |
0 | 147 |
if (tile == _backup_orders_tile) { |
148 |
_backup_orders_tile = 0; |
|
149 |
RestoreVehicleOrders(v, _backup_orders_data); |
|
150 |
} |
|
151 |
ShowTrainViewWindow(v); |
|
152 |
} |
|
153 |
||
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
154 |
static void engine_drawing_loop(int *x, int *y, int *pos, int *sel, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
155 |
int *selected_id, byte railtype, byte show_max, bool is_engine) |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
156 |
{ |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
157 |
int i; |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
158 |
|
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
159 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
160 |
const Engine *e = GetEngine(i); |
539 | 161 |
const RailVehicleInfo *rvi = RailVehInfo(i); |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
162 |
|
2032
25f8f4da05a0
(svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents:
1986
diff
changeset
|
163 |
if (!IsCompatibleRail(railtype, e->railtype) || !(rvi->flags & RVI_WAGON) != is_engine || |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
164 |
!HASBIT(e->player_avail, _local_player)) |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
165 |
continue; |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
166 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
167 |
if (*sel == 0) |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
168 |
*selected_id = i; |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
169 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
170 |
if (IS_INT_INSIDE(--*pos, -show_max, 0)) { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
171 |
DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10); |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
172 |
DrawTrainEngine(*x + 29, *y + 6 + _traininfo_vehicle_pitch, i, |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
173 |
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
174 |
*y += 14; |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
175 |
} |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
176 |
--*sel; |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
177 |
} |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
178 |
} |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
179 |
|
0 | 180 |
static void NewRailVehicleWndProc(Window *w, WindowEvent *e) |
181 |
{ |
|
182 |
switch(e->event) { |
|
183 |
case WE_PAINT: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
184 |
|
0 | 185 |
if (w->window_number == 0) |
186 |
SETBIT(w->disabled_state, 5); |
|
187 |
||
188 |
{ |
|
189 |
int count = 0; |
|
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
190 |
byte railtype = WP(w,buildtrain_d).railtype; |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
191 |
int i; |
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
192 |
|
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
193 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
194 |
const Engine *e = GetEngine(i); |
2032
25f8f4da05a0
(svn r2541) -Feature: Modified IsCompatibleRail so that an engine can move on more
celestar
parents:
1986
diff
changeset
|
195 |
if (IsCompatibleRail(railtype, e->railtype) |
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
196 |
&& HASBIT(e->player_avail, _local_player)) |
0 | 197 |
count++; |
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
198 |
} |
0 | 199 |
SetVScrollCount(w, count); |
200 |
} |
|
201 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
202 |
SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
0 | 203 |
DrawWindowWidgets(w); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
204 |
|
0 | 205 |
{ |
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
206 |
byte railtype = WP(w,buildtrain_d).railtype; |
0 | 207 |
int sel = WP(w,buildtrain_d).sel_index; |
208 |
int pos = w->vscroll.pos; |
|
209 |
int x = 1; |
|
210 |
int y = 15; |
|
211 |
int selected_id = -1; |
|
212 |
||
460
7506c66ce4c3
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
420
diff
changeset
|
213 |
/* Ensure that custom engines which substituted wagons |
524
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
214 |
* are sorted correctly. |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
215 |
* XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
216 |
* engines to get more types.. Stays here until we have our own format |
bcbcedbf5ccd
(svn r854) -Fix [1070274] Invisible trains. Weird macros and MSVC optimizing don't always mix. (Tron)
darkvater
parents:
517
diff
changeset
|
217 |
* then it is exit!!! */ |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
218 |
engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
219 |
engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons |
0 | 220 |
|
221 |
WP(w,buildtrain_d).sel_engine = selected_id; |
|
222 |
||
223 |
if (selected_id != -1) { |
|
539 | 224 |
const RailVehicleInfo *rvi = RailVehInfo(selected_id); |
0 | 225 |
|
226 |
if (!(rvi->flags & RVI_WAGON)) { |
|
227 |
/* it's an engine */ |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
228 |
DrawTrainEnginePurchaseInfo(2, w->widget[4].top + 1,selected_id); |
0 | 229 |
} else { |
230 |
/* it's a wagon */ |
|
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
231 |
DrawTrainWagonPurchaseInfo(2, w->widget[4].top + 1, selected_id); |
0 | 232 |
} |
233 |
} |
|
234 |
} |
|
235 |
break; |
|
236 |
||
237 |
case WE_CLICK: { |
|
238 |
switch(e->click.widget) { |
|
239 |
case 2: { |
|
240 |
uint i = (e->click.pt.y - 14) / 14; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
241 |
if (i < w->vscroll.cap) { |
0 | 242 |
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; |
243 |
SetWindowDirty(w); |
|
244 |
} |
|
245 |
} break; |
|
246 |
case 5: { |
|
247 |
int sel_eng; |
|
248 |
sel_eng = WP(w,buildtrain_d).sel_engine; |
|
249 |
if (sel_eng != -1) |
|
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
539
diff
changeset
|
250 |
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 | 251 |
} break; |
968
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
252 |
case 6: { /* rename */ |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
253 |
int sel_eng = WP(w,buildtrain_d).sel_engine; |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
254 |
if (sel_eng != -1) { |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
255 |
WP(w,buildtrain_d).rename_engine = sel_eng; |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
256 |
ShowQueryString(GetCustomEngineName(sel_eng), |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
257 |
STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number); |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
258 |
} |
84a870c7a585
(svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents:
919
diff
changeset
|
259 |
} break; |
0 | 260 |
} |
261 |
} break; |
|
262 |
||
263 |
case WE_4: |
|
264 |
if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) { |
|
265 |
DeleteWindow(w); |
|
266 |
} |
|
267 |
break; |
|
268 |
||
269 |
case WE_ON_EDIT_TEXT: { |
|
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
270 |
if (e->edittext.str[0] != '\0') { |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
271 |
_cmd_text = e->edittext.str; |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
272 |
DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
273 |
CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE)); |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
274 |
} |
0 | 275 |
} break; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
276 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
277 |
case WE_RESIZE: { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
278 |
if (e->sizing.diff.y == 0) |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
279 |
break; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
280 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
281 |
w->vscroll.cap += e->sizing.diff.y / 14; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
282 |
w->widget[2].unkA = (w->vscroll.cap << 8) + 1; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
283 |
} break; |
0 | 284 |
} |
285 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
286 |
|
0 | 287 |
static const Widget _new_rail_vehicle_widgets[] = { |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
288 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1017
b09bae77a850
(svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents:
1006
diff
changeset
|
289 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
893
f4698309dec7
(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
|
290 |
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, |
f4698309dec7
(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
|
291 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
292 |
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 197, 0x0, STR_NULL}, |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
293 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 198, 209, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
294 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 198, 209, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, |
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
295 |
{ 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
|
296 |
{ WIDGETS_END}, |
0 | 297 |
}; |
298 |
||
299 |
static const WindowDesc _new_rail_vehicle_desc = { |
|
1908
2fa391fed79a
(svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
300 |
-1, -1, 228, 210, |
0 | 301 |
WC_BUILD_VEHICLE,0, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
302 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
0 | 303 |
_new_rail_vehicle_widgets, |
304 |
NewRailVehicleWndProc |
|
305 |
}; |
|
306 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
307 |
static void ShowBuildTrainWindow(TileIndex tile) |
0 | 308 |
{ |
309 |
Window *w; |
|
310 |
||
311 |
DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
312 |
||
313 |
w = AllocateWindowDesc(&_new_rail_vehicle_desc); |
|
314 |
w->window_number = tile; |
|
315 |
w->vscroll.cap = 8; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
316 |
w->widget[2].unkA = (w->vscroll.cap << 8) + 1; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
317 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
318 |
w->resize.step_height = 14; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
319 |
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
|
320 |
|
0 | 321 |
if (tile != 0) { |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
322 |
w->caption_color = GetTileOwner(tile); |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2032
diff
changeset
|
323 |
WP(w,buildtrain_d).railtype = _m[tile].m3 & 0xF; |
0 | 324 |
} else { |
325 |
w->caption_color = _local_player; |
|
1962
8254df1b359b
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1938
diff
changeset
|
326 |
WP(w,buildtrain_d).railtype = GetPlayer(_local_player)->max_railtype - 1; |
0 | 327 |
} |
328 |
} |
|
329 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
330 |
static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection) |
0 | 331 |
{ |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
332 |
int max_x = x + count * 29; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
333 |
|
0 | 334 |
do { |
335 |
if (--skip < 0) { |
|
336 |
int image = GetTrainImage(v, 6); |
|
337 |
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
338 |
int width = v->u.rail.cached_veh_length * 3; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
339 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
340 |
if (x + width + 4 <= max_x) { |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
341 |
if (v->vehstatus & VS_CRASHED) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
342 |
ormod = PALETTE_CRASH; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
343 |
DrawSprite(image | ormod, x + 14, y + 6 + _traininfo_vehicle_pitch); |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
344 |
if (v->index == selection) |
1938
70baf462aff1
(svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents:
1926
diff
changeset
|
345 |
DrawFrameRect(x - 1, y - 1, x + width + 4, y + 12, 15, FR_BORDERONLY); |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
346 |
} |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
347 |
x += width + 5; |
0 | 348 |
} |
349 |
||
350 |
if (!(v = v->next)) |
|
351 |
break; |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
352 |
} while (x < max_x); |
0 | 353 |
} |
354 |
||
355 |
static void DrawTrainDepotWindow(Window *w) |
|
356 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
357 |
TileIndex tile; |
0 | 358 |
Vehicle *v, *u; |
359 |
int num,x,y,i, hnum; |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
360 |
Depot *depot; |
0 | 361 |
|
362 |
tile = w->window_number; |
|
363 |
||
364 |
/* setup disabled buttons */ |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
365 |
w->disabled_state = |
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
366 |
IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8)); |
0 | 367 |
|
368 |
/* determine amount of items for scroller */ |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
369 |
num = 0; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
370 |
hnum = 1; |
0 | 371 |
FOR_ALL_VEHICLES(v) { |
372 |
if (v->type == VEH_Train && |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
373 |
(v->subtype == TS_Front_Engine || v->subtype == TS_Free_Car) && |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
374 |
v->tile == tile && |
0 | 375 |
v->u.rail.track == 0x80) { |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
376 |
num++; |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
377 |
// determine number of items in the X direction. |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
378 |
if (v->subtype == TS_Front_Engine) { |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
379 |
i = 0; |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
380 |
u = v; |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
381 |
do i++; while ((u = u->next) != NULL); |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
382 |
if (i > hnum) hnum = i; |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
383 |
} |
0 | 384 |
} |
385 |
} |
|
914
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
386 |
|
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
387 |
/* Always have 1 empty row, so people can change the setting of the train */ |
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
388 |
num++; |
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
389 |
|
0 | 390 |
SetVScrollCount(w, num); |
391 |
SetHScrollCount(w, hnum); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
392 |
|
0 | 393 |
/* locate the depot struct */ |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
394 |
depot = GetDepotByTile(tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
395 |
assert(depot != NULL); |
0 | 396 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
397 |
SetDParam(0, depot->town_index); |
0 | 398 |
DrawWindowWidgets(w); |
399 |
||
400 |
x = 2; |
|
401 |
y = 15; |
|
402 |
num = w->vscroll.pos; |
|
403 |
||
404 |
// draw all trains |
|
405 |
FOR_ALL_VEHICLES(v) { |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
406 |
if (v->type == VEH_Train && v->subtype == TS_Front_Engine && |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
407 |
v->tile == tile && v->u.rail.track == 0x80 && |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
408 |
--num < 0 && num >= -w->vscroll.cap) { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
409 |
DrawTrainImage(v, x+21, y, w->hscroll.cap, w->hscroll.pos, WP(w,traindepot_d).sel); |
22 | 410 |
/* Draw the train number */ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
411 |
SetDParam(0, v->unitnumber); |
0 | 412 |
DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0); |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
413 |
|
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
414 |
/*Draw the train counter */ |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
415 |
i = 0; |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
416 |
u = v; |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
417 |
do { |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
418 |
i += u->u.rail.cached_veh_length + 1; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
419 |
} while ( (u=u->next) != NULL); //Determine length of train |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
420 |
|
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
421 |
SetDParam(0, (i + 8) / 9); //Set the counter |
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
422 |
DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); //Draw the counter |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
423 |
|
22 | 424 |
/* Draw the pretty flag */ |
0 | 425 |
DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y); |
426 |
||
427 |
y += 14; |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
// draw all remaining vehicles |
|
432 |
FOR_ALL_VEHICLES(v) { |
|
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
433 |
if (v->type == VEH_Train && v->subtype == TS_Free_Car && |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1977
diff
changeset
|
434 |
v->tile == tile && v->u.rail.track == 0x80 && |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
435 |
--num < 0 && num >= -w->vscroll.cap) { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
436 |
DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 0, WP(w,traindepot_d).sel); |
0 | 437 |
DrawString(x, y+2, STR_8816, 0); |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1017
diff
changeset
|
438 |
|
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
439 |
/*Draw the train counter */ |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
440 |
i = 0; |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
441 |
u = v; |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
442 |
do i++; while ( (u=u->next) != NULL); //Determine length of train |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
443 |
SetDParam(0, i); //Set the counter |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
444 |
DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); //Draw the counter |
0 | 445 |
y += 14; |
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
typedef struct GetDepotVehiclePtData { |
|
451 |
Vehicle *head; |
|
452 |
Vehicle *wagon; |
|
453 |
} GetDepotVehiclePtData; |
|
454 |
||
455 |
static int GetVehicleFromTrainDepotWndPt(Window *w, int x, int y, GetDepotVehiclePtData *d) |
|
456 |
{ |
|
457 |
int row; |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
458 |
int skip = 0; |
0 | 459 |
Vehicle *v; |
460 |
||
461 |
x = x - 23; |
|
462 |
||
463 |
row = (y - 14) / 14; |
|
914
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
464 |
if ( (uint) row >= w->vscroll.cap) |
0 | 465 |
return 1; /* means err */ |
466 |
||
467 |
row += w->vscroll.pos; |
|
468 |
||
469 |
/* go through all the locomotives */ |
|
470 |
FOR_ALL_VEHICLES(v) { |
|
471 |
if (v->type == VEH_Train && |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
472 |
v->subtype == TS_Front_Engine && |
0 | 473 |
v->tile == w->window_number && |
474 |
v->u.rail.track == 0x80 && |
|
475 |
--row < 0) { |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
476 |
skip = w->hscroll.pos; |
0 | 477 |
goto found_it; |
478 |
} |
|
479 |
} |
|
480 |
||
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
481 |
x -= 29; /* free wagons don't have an initial loco. */ |
0 | 482 |
|
483 |
/* and then the list of free wagons */ |
|
484 |
FOR_ALL_VEHICLES(v) { |
|
485 |
if (v->type == VEH_Train && |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
486 |
v->subtype == TS_Free_Car && |
0 | 487 |
v->tile == w->window_number && |
488 |
v->u.rail.track == 0x80 && |
|
489 |
--row < 0) |
|
490 |
goto found_it; |
|
491 |
} |
|
492 |
||
493 |
d->head = NULL; |
|
494 |
d->wagon = NULL; |
|
495 |
||
496 |
/* didn't find anything, get out */ |
|
497 |
return 0; |
|
498 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
499 |
found_it: |
0 | 500 |
d->head = d->wagon = v; |
501 |
||
502 |
/* either pressed the flag or the number, but only when it's a loco */ |
|
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
503 |
if (x < 0 && v->subtype == TS_Front_Engine) |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
504 |
return (x >= -10) ? -2 : -1; |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
505 |
|
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
506 |
// skip vehicles that are scrolled off the left side |
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
507 |
while (skip--) v = v->next; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
508 |
|
0 | 509 |
/* find the vehicle in this row that was clicked */ |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
510 |
while ((x -= v->u.rail.cached_veh_length * 3 + 5) >= 0) { |
0 | 511 |
v = v->next; |
512 |
if (v == NULL) break; |
|
513 |
} |
|
514 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
515 |
d->wagon = v; |
0 | 516 |
|
517 |
return 0; |
|
518 |
} |
|
519 |
||
520 |
static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) |
|
521 |
{ |
|
522 |
Vehicle *v; |
|
523 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
524 |
v = GetVehicle(sel); |
0 | 525 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
526 |
if (/*v->subtype == TS_Front_Engine ||*/ v == wagon) |
0 | 527 |
return; |
528 |
||
529 |
if (wagon == NULL) { |
|
530 |
if (head != NULL) |
|
531 |
wagon = GetLastVehicleInChain(head); |
|
532 |
} else { |
|
533 |
wagon = GetPrevVehicleInChain(wagon); |
|
534 |
if (wagon == NULL) |
|
535 |
return; |
|
536 |
} |
|
537 |
||
538 |
if (wagon == v) |
|
539 |
return; |
|
540 |
||
541 |
DoCommandP(v->tile, v->index + ((wagon==NULL ? (uint32)-1 : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
|
542 |
} |
|
543 |
||
544 |
static void TrainDepotClickTrain(Window *w, int x, int y) |
|
545 |
{ |
|
546 |
GetDepotVehiclePtData gdvp; |
|
547 |
int mode, sel; |
|
548 |
Vehicle *v; |
|
549 |
||
550 |
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
|
551 |
|
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
|
552 |
// share / copy orders |
0 | 553 |
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
|
554 |
|
0 | 555 |
v = gdvp.wagon; |
556 |
||
557 |
switch(mode) { |
|
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
|
558 |
case 0: // start dragging of vehicle |
0 | 559 |
sel = (int16)WP(w,traindepot_d).sel; |
560 |
if (sel != -1) { |
|
561 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
562 |
TrainDepotMoveVehicle(v, sel, gdvp.head); |
|
563 |
} else if (v != NULL) { |
|
564 |
WP(w,traindepot_d).sel = v->index; |
|
565 |
SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w); |
|
566 |
SetWindowDirty(w); |
|
567 |
} |
|
568 |
break; |
|
569 |
||
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
|
570 |
case -1: // show info window |
0 | 571 |
ShowTrainViewWindow(v); |
572 |
break; |
|
573 |
||
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
|
574 |
case -2: // click start/stop flag |
0 | 575 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); |
576 |
break; |
|
577 |
} |
|
578 |
} |
|
579 |
||
580 |
static void TrainDepotWndProc(Window *w, WindowEvent *e) |
|
581 |
{ |
|
582 |
switch(e->event) { |
|
583 |
case WE_PAINT: |
|
584 |
DrawTrainDepotWindow(w); |
|
585 |
break; |
|
586 |
||
587 |
case WE_CLICK: { |
|
588 |
switch(e->click.widget) { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
589 |
case 8: |
0 | 590 |
ShowBuildTrainWindow(w->window_number); |
591 |
break; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
592 |
case 9: |
0 | 593 |
ScrollMainWindowToTile(w->window_number); |
594 |
break; |
|
982
d3ce4d6a65f8
(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
|
595 |
case 6: |
0 | 596 |
TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y); |
597 |
break; |
|
598 |
} |
|
599 |
} break; |
|
600 |
||
601 |
case WE_DESTROY: |
|
602 |
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); |
|
603 |
break; |
|
604 |
||
605 |
case WE_DRAGDROP: { |
|
606 |
switch(e->click.widget) { |
|
982
d3ce4d6a65f8
(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
|
607 |
case 4: case 5: { |
0 | 608 |
Vehicle *v; |
609 |
int sell_cmd; |
|
610 |
||
611 |
/* sell vehicle */ |
|
612 |
if (w->disabled_state & (1 << e->click.widget)) |
|
613 |
return; |
|
614 |
||
615 |
if (WP(w,traindepot_d).sel == INVALID_VEHICLE) |
|
616 |
return; |
|
617 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
618 |
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
|
619 |
|
0 | 620 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
621 |
SetWindowDirty(w); |
|
622 |
||
623 |
HandleButtonClick(w, e->click.widget); |
|
624 |
||
982
d3ce4d6a65f8
(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
|
625 |
sell_cmd = (e->click.widget == 5 || _ctrl_pressed) ? 1 : 0; |
0 | 626 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
627 |
if (v->subtype != TS_Front_Engine) { |
0 | 628 |
DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)); |
629 |
} else { |
|
630 |
_backup_orders_tile = v->tile; |
|
631 |
BackupVehicleOrders(v, _backup_orders_data); |
|
632 |
if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE))) |
|
633 |
_backup_orders_tile = 0; |
|
634 |
} |
|
635 |
} break; |
|
636 |
||
982
d3ce4d6a65f8
(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
|
637 |
case 6: { |
0 | 638 |
GetDepotVehiclePtData gdvp; |
639 |
VehicleID sel = WP(w,traindepot_d).sel; |
|
640 |
||
641 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
642 |
SetWindowDirty(w); |
|
643 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
644 |
if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 && |
0 | 645 |
sel != INVALID_VEHICLE) { |
646 |
if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { |
|
647 |
TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
648 |
} else if (gdvp.head != NULL && gdvp.head->subtype == TS_Front_Engine) { |
0 | 649 |
ShowTrainViewWindow(gdvp.head); |
650 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
651 |
} |
0 | 652 |
} break; |
653 |
||
654 |
default: |
|
655 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
656 |
SetWindowDirty(w); |
|
657 |
break; |
|
658 |
} |
|
659 |
} break; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
660 |
case WE_RESIZE: { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
661 |
/* Update the scroll + matrix */ |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
662 |
w->vscroll.cap += e->sizing.diff.y / 14; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
663 |
w->hscroll.cap += e->sizing.diff.x / 29; |
982
d3ce4d6a65f8
(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
|
664 |
w->widget[6].unkA = (w->vscroll.cap << 8) + 1; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
665 |
} break; |
0 | 666 |
} |
667 |
} |
|
668 |
||
669 |
static const Widget _train_depot_widgets[] = { |
|
982
d3ce4d6a65f8
(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
|
670 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
671 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
672 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 349, 360, 0, 13, 0x0, STR_STICKY_BUTTON}, |
0 | 673 |
|
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
674 |
{ WWT_PANEL, RESIZE_LRB, 14, 326, 348, 14, 13, 0x0, STR_NULL}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
675 |
{ WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
676 |
{ WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 55, 109, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
677 |
|
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
678 |
{ WWT_MATRIX, RESIZE_RB, 14, 0, 325, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
679 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 349, 360, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
914
4359607898f7
(svn r1401) -Fix: glitches in train-depot GUI (tnx to Hackykid)
truelight
parents:
894
diff
changeset
|
680 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 167, 110, 121, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE}, |
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
681 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 168, 348, 110, 121, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN}, |
1658
ed5d679c5122
(svn r2162) - Fix: Tooltips of horizontal scrollbars were wrong; they now say left/right instead of up/down
Darkvater
parents:
1485
diff
changeset
|
682 |
{ WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 325, 98, 109, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, |
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
683 |
{ WWT_PANEL, RESIZE_RTB, 14, 349, 348, 110, 121, 0x0, STR_NULL}, |
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
684 |
{ 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
|
685 |
{ WIDGETS_END}, |
0 | 686 |
}; |
687 |
||
688 |
static const WindowDesc _train_depot_desc = { |
|
1002
9d83f1842257
(svn r1500) -Feature: Train window shows now the number of vehicles per row (mpetrov)
celestar
parents:
982
diff
changeset
|
689 |
-1, -1, 361, 122, |
0 | 690 |
WC_VEHICLE_DEPOT,0, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
691 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 692 |
_train_depot_widgets, |
693 |
TrainDepotWndProc |
|
694 |
}; |
|
695 |
||
696 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
697 |
void ShowTrainDepotWindow(TileIndex tile) |
0 | 698 |
{ |
699 |
Window *w; |
|
700 |
||
701 |
w = AllocateWindowDescFront(&_train_depot_desc, tile); |
|
702 |
if (w) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
703 |
w->caption_color = GetTileOwner(w->window_number); |
0 | 704 |
w->vscroll.cap = 6; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
705 |
w->hscroll.cap = 10; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
706 |
w->resize.step_width = 29; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
707 |
w->resize.step_height = 14; |
0 | 708 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
709 |
_backup_orders_tile = 0; |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
static void RailVehicleRefitWndProc(Window *w, WindowEvent *e) |
|
714 |
{ |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
715 |
switch (e->event) { |
0 | 716 |
case WE_PAINT: { |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
717 |
const Vehicle *v = GetVehicle(w->window_number); |
0 | 718 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
719 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
720 |
SetDParam(1, v->unitnumber); |
0 | 721 |
DrawWindowWidgets(w); |
722 |
||
723 |
DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0); |
|
724 |
||
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
725 |
/* TODO: Support for custom GRFSpecial-specified refitting! --pasky */ |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
726 |
WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w, refit_d).sel); |
382
9f80e5141ef1
(svn r572) -newgrf: Support for custom (newGRF-yielded) refit masks for trains and aircrafts (pasky).
darkvater
parents:
338
diff
changeset
|
727 |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
728 |
if (WP(w,refit_d).cargo != CT_INVALID) { |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
729 |
int32 cost = DoCommandByTile(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_RAIL_VEHICLE); |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
730 |
if (!CmdFailed(cost)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
731 |
SetDParam(2, cost); |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2049
diff
changeset
|
732 |
SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
733 |
SetDParam(1, _returned_refit_amount); |
0 | 734 |
DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0); |
735 |
} |
|
736 |
} |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
737 |
} break; |
0 | 738 |
|
739 |
case WE_CLICK: |
|
740 |
switch(e->click.widget) { |
|
741 |
case 2: { /* listbox */ |
|
742 |
int y = e->click.pt.y - 25; |
|
743 |
if (y >= 0) { |
|
744 |
WP(w,refit_d).sel = y / 10; |
|
745 |
SetWindowDirty(w); |
|
746 |
} |
|
747 |
} break; |
|
748 |
case 4: /* refit button */ |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
749 |
if (WP(w,refit_d).cargo != CT_INVALID) { |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
750 |
const Vehicle *v = GetVehicle(w->window_number); |
0 | 751 |
if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE))) |
752 |
DeleteWindow(w); |
|
753 |
} |
|
754 |
break; |
|
755 |
} |
|
756 |
break; |
|
757 |
} |
|
758 |
} |
|
759 |
||
760 |
||
761 |
static const Widget _rail_vehicle_refit_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
762 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
763 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
764 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
765 |
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
766 |
{ 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
|
767 |
{ WIDGETS_END}, |
0 | 768 |
}; |
769 |
||
770 |
static const WindowDesc _rail_vehicle_refit_desc = { |
|
771 |
-1,-1, 240, 170, |
|
772 |
WC_VEHICLE_REFIT,WC_VEHICLE_VIEW, |
|
773 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
774 |
_rail_vehicle_refit_widgets, |
|
775 |
RailVehicleRefitWndProc, |
|
776 |
}; |
|
777 |
||
778 |
static void ShowRailVehicleRefitWindow(Vehicle *v) |
|
779 |
{ |
|
780 |
Window *w; |
|
781 |
DeleteWindowById(WC_VEHICLE_REFIT, v->index); |
|
782 |
_alloc_wnd_parent_num = v->index; |
|
783 |
w = AllocateWindowDesc(&_rail_vehicle_refit_desc); |
|
784 |
w->window_number = v->index; |
|
785 |
w->caption_color = v->owner; |
|
786 |
WP(w,refit_d).sel = -1; |
|
787 |
} |
|
788 |
||
789 |
static Widget _train_view_widgets[] = { |
|
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
790 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
791 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
792 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
793 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
794 |
{ WWT_6, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
795 |
{ WWT_PUSHIMGBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
796 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
797 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
798 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
799 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
800 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
801 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
802 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
803 |
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
804 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL }, |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
805 |
{ WIDGETS_END } |
0 | 806 |
}; |
807 |
||
808 |
static void TrainViewWndProc(Window *w, WindowEvent *e) |
|
809 |
{ |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
810 |
switch (e->event) { |
0 | 811 |
case WE_PAINT: { |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
812 |
const Vehicle *v, *u; |
0 | 813 |
StringID str; |
814 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
815 |
v = GetVehicle(w->window_number); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
816 |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
817 |
w->disabled_state = (v->owner == _local_player) ? 0 : 0x380; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
818 |
|
1387
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
819 |
SETBIT(w->disabled_state, 12); |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
820 |
|
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
821 |
/* See if any vehicle can be refitted */ |
1387
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
822 |
for ( u = v; u != NULL; u = u->next) { |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
823 |
if (_engine_refit_masks[u->engine_type] != 0 || |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1790
diff
changeset
|
824 |
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) { |
1387
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
825 |
CLRBIT(w->disabled_state, 12); |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
826 |
/* We have a refittable carriage, bail out */ |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
827 |
break; |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
828 |
} |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
829 |
} |
bc0131072af9
(svn r1891) -Fix: [ 1143587 ] carriages of newgrfs can be refitted again
celestar
parents:
1330
diff
changeset
|
830 |
|
0 | 831 |
/* draw widgets & caption */ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
832 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
833 |
SetDParam(1, v->unitnumber); |
0 | 834 |
DrawWindowWidgets(w); |
835 |
||
836 |
if (v->u.rail.crash_anim_pos != 0) { |
|
837 |
str = STR_8863_CRASHED; |
|
838 |
} else if (v->breakdown_ctr == 1) { |
|
839 |
str = STR_885C_BROKEN_DOWN; |
|
840 |
} else if (v->vehstatus & VS_STOPPED) { |
|
841 |
if (v->u.rail.last_speed == 0) { |
|
842 |
str = STR_8861_STOPPED; |
|
843 |
} else { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
844 |
SetDParam(0, v->u.rail.last_speed * 10 >> 4); |
0 | 845 |
str = STR_TRAIN_STOPPING + _patches.vehicle_speed; |
846 |
} |
|
847 |
} else { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
848 |
switch (v->current_order.type) { |
0 | 849 |
case OT_GOTO_STATION: { |
850 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
851 |
SetDParam(0, v->current_order.station); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
852 |
SetDParam(1, v->u.rail.last_speed * 10 >> 4); |
0 | 853 |
} break; |
854 |
||
855 |
case OT_GOTO_DEPOT: { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
856 |
Depot *dep = GetDepot(v->current_order.station); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
857 |
SetDParam(0, dep->town_index); |
0 | 858 |
str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
859 |
SetDParam(1, v->u.rail.last_speed * 10 >> 4); |
0 | 860 |
} break; |
861 |
||
862 |
case OT_LOADING: |
|
863 |
case OT_LEAVESTATION: |
|
864 |
str = STR_882F_LOADING_UNLOADING; |
|
865 |
break; |
|
866 |
||
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
382
diff
changeset
|
867 |
case OT_GOTO_WAYPOINT: { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
868 |
SetDParam(0, v->current_order.station); |
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
382
diff
changeset
|
869 |
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
870 |
SetDParam(1, v->u.rail.last_speed * 10 >> 4); |
0 | 871 |
break; |
872 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
873 |
|
0 | 874 |
default: |
875 |
if (v->num_orders == 0) { |
|
876 |
str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
877 |
SetDParam(0, v->u.rail.last_speed * 10 >> 4); |
0 | 878 |
} else |
879 |
str = STR_EMPTY; |
|
880 |
break; |
|
881 |
} |
|
882 |
} |
|
883 |
||
2103
a2b3106d33d5
(svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents:
2084
diff
changeset
|
884 |
/* draw the flag plus orders */ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
885 |
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1); |
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
886 |
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0); |
0 | 887 |
DrawWindowViewport(w); |
888 |
} break; |
|
889 |
||
890 |
case WE_CLICK: { |
|
891 |
int wid = e->click.widget; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
892 |
Vehicle *v = GetVehicle(w->window_number); |
0 | 893 |
|
894 |
switch(wid) { |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
895 |
case 5: /* start/stop train */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
896 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); |
0 | 897 |
break; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
898 |
case 6: /* center main view */ |
0 | 899 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
900 |
break; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
901 |
case 7: /* goto depot */ |
601
3d15c18e3a8e
(svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents:
588
diff
changeset
|
902 |
/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ |
3d15c18e3a8e
(svn r1025) -Fix: [Network] [ 1083687 ] Sending to depot caused desync because the
truelight
parents:
588
diff
changeset
|
903 |
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 | 904 |
break; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
905 |
case 8: /* force proceed */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
906 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL)); |
0 | 907 |
break; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
908 |
case 9: /* reverse direction */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
909 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION)); |
0 | 910 |
break; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
911 |
case 10: /* show train orders */ |
0 | 912 |
ShowOrdersWindow(v); |
913 |
break; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
914 |
case 11: /* show train details */ |
0 | 915 |
ShowTrainDetailsWindow(v); |
916 |
break; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
727
diff
changeset
|
917 |
case 12: |
0 | 918 |
ShowRailVehicleRefitWindow(v); |
919 |
break; |
|
920 |
} |
|
921 |
} break; |
|
922 |
||
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
923 |
case WE_RESIZE: |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
924 |
w->viewport->width += e->sizing.diff.x; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
925 |
w->viewport->height += e->sizing.diff.y; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
926 |
w->viewport->virtual_width += e->sizing.diff.x; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
927 |
w->viewport->virtual_height += e->sizing.diff.y; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
928 |
break; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
929 |
|
0 | 930 |
case WE_DESTROY: |
338
37500d4214f3
(svn r514) -Fix: [1053397] Refit Train Window Stays Open
tron
parents:
243
diff
changeset
|
931 |
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); |
0 | 932 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
933 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
|
934 |
break; |
|
935 |
||
936 |
case WE_MOUSELOOP: { |
|
937 |
Vehicle *v; |
|
938 |
uint32 h; |
|
939 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
940 |
v = GetVehicle(w->window_number); |
0 | 941 |
assert(v->type == VEH_Train); |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
942 |
h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9) : (1 << 12); |
0 | 943 |
if (h != w->hidden_state) { |
944 |
w->hidden_state = h; |
|
945 |
SetWindowDirty(w); |
|
946 |
} |
|
947 |
break; |
|
948 |
} |
|
949 |
||
950 |
} |
|
951 |
} |
|
952 |
||
953 |
static const WindowDesc _train_view_desc = { |
|
954 |
-1,-1, 250, 134, |
|
955 |
WC_VEHICLE_VIEW,0, |
|
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1402
diff
changeset
|
956 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 957 |
_train_view_widgets, |
958 |
TrainViewWndProc |
|
959 |
}; |
|
960 |
||
961 |
void ShowTrainViewWindow(Vehicle *v) |
|
962 |
{ |
|
963 |
Window *w; |
|
964 |
||
965 |
w = AllocateWindowDescFront(&_train_view_desc,v->index); |
|
966 |
if (w) { |
|
967 |
w->caption_color = v->owner; |
|
968 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0); |
|
969 |
} |
|
970 |
} |
|
971 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
972 |
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) |
0 | 973 |
{ |
974 |
int num; |
|
975 |
StringID str; |
|
976 |
||
977 |
if (v->cargo_cap != 0) { |
|
978 |
num = v->cargo_count; |
|
979 |
str = STR_8812_EMPTY; |
|
980 |
if (num != 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
981 |
SetDParam(0, v->cargo_type); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
982 |
SetDParam(1, num); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
983 |
SetDParam(2, v->cargo_source); |
0 | 984 |
str = STR_8813_FROM; |
985 |
} |
|
986 |
DrawString(x, y, str, 0); |
|
987 |
} |
|
988 |
} |
|
989 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
990 |
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y) |
0 | 991 |
{ |
540
2987d7976ea2
(svn r924) Use RailVehInfo() instead of &_rail_vehicle_info[]
tron
parents:
539
diff
changeset
|
992 |
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); |
0 | 993 |
|
994 |
if (!(rvi->flags & RVI_WAGON)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
995 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
996 |
SetDParam(1, v->build_year + 1920); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
997 |
SetDParam(2, v->value); |
0 | 998 |
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); |
999 |
} else { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1000 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1001 |
SetDParam(1, v->value); |
0 | 1002 |
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
|
1003 |
} |
0 | 1004 |
} |
1005 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1006 |
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y) |
0 | 1007 |
{ |
1008 |
if (v->cargo_cap != 0) { |
|
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2049
diff
changeset
|
1009 |
SetDParam(0, _cargoc.names_long[v->cargo_type]); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1010 |
SetDParam(1, v->cargo_cap); |
0 | 1011 |
DrawString(x, y, STR_013F_CAPACITY, 0); |
1012 |
} |
|
1013 |
} |
|
1014 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1015 |
typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y); |
0 | 1016 |
|
1017 |
static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = { |
|
1018 |
TrainDetailsCargoTab, |
|
1019 |
TrainDetailsInfoTab, |
|
1020 |
TrainDetailsCapacityTab, |
|
1021 |
}; |
|
1022 |
||
1023 |
static void DrawTrainDetailsWindow(Window *w) |
|
1024 |
{ |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1025 |
const Vehicle *v, *u; |
0 | 1026 |
uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo) |
1027 |
int i,num,x,y,sel; |
|
1028 |
StringID str; |
|
1029 |
byte det_tab = WP(w, traindetails_d).tab; |
|
1030 |
||
1031 |
/* Count number of vehicles */ |
|
1032 |
num = 0; |
|
1033 |
||
1034 |
// det_tab == 3 <-- Total Cargo tab |
|
1035 |
if (det_tab == 3) // reset tot_cargo array to 0 values |
|
1036 |
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
|
1037 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1038 |
u = v = GetVehicle(w->window_number); |
0 | 1039 |
do { |
1040 |
if (det_tab != 3) |
|
1041 |
num++; |
|
1042 |
else { |
|
1043 |
tot_cargo[u->cargo_type][0] += u->cargo_count; |
|
1044 |
tot_cargo[u->cargo_type][1] += u->cargo_cap; |
|
1045 |
} |
|
1046 |
} while ( (u = u->next) != NULL); |
|
1047 |
||
1048 |
/* set scroll-amount seperately from counting, as to not |
|
1049 |
compute num double for more carriages of the same type |
|
1050 |
*/ |
|
1051 |
if (det_tab == 3) { |
|
1052 |
for (i = 0; i != NUM_CARGO; i++) { |
|
1053 |
if (tot_cargo[i][1] > 0) // only count carriages that the train has |
|
1054 |
num++; |
|
1055 |
} |
|
1056 |
num++; // needs one more because first line is description string |
|
1057 |
} |
|
1058 |
||
1059 |
SetVScrollCount(w, num); |
|
1060 |
||
1061 |
w->disabled_state = 1 << (det_tab + 9); |
|
1062 |
if (v->owner != _local_player) |
|
1063 |
w->disabled_state |= (1 << 2); |
|
1064 |
||
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
|
1065 |
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
|
1066 |
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
|
1067 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1068 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1069 |
SetDParam(1, v->unitnumber); |
0 | 1070 |
DrawWindowWidgets(w); |
1071 |
||
1072 |
num = v->age / 366; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1073 |
SetDParam(1, num); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1074 |
|
0 | 1075 |
x = 2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1076 |
|
0 | 1077 |
str = STR_0199_YEAR; |
1078 |
if (num != 1) { |
|
1079 |
str += STR_019A_YEARS - STR_0199_YEAR; |
|
1080 |
if ((uint16)(v->max_age - 366) < v->age) |
|
1081 |
str += STR_019B_YEARS - STR_019A_YEARS; |
|
1082 |
} |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1083 |
SetDParam(0, str); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1084 |
SetDParam(2, v->max_age / 366); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1085 |
SetDParam(3, GetTrainRunningCost(v) >> 8); |
0 | 1086 |
DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); |
1087 |
||
1905
c53f8d71f9b6
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1901
diff
changeset
|
1088 |
SetDParam(2, v->u.rail.cached_max_speed * 10 >> 4); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1089 |
SetDParam(1, v->u.rail.cached_power); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1090 |
SetDParam(0, v->u.rail.cached_weight); |
0 | 1091 |
DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_MAX_SPEED, 0); |
1092 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1093 |
SetDParam(0, v->profit_this_year); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1094 |
SetDParam(1, v->profit_last_year); |
0 | 1095 |
DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
1096 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1097 |
SetDParam(0, 100 * (v->reliability>>8) >> 8); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1098 |
SetDParam(1, v->breakdowns_since_last_service); |
0 | 1099 |
DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0); |
1100 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1101 |
SetDParam(0, v->service_interval); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1102 |
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
|
1103 |
DrawString(x + 11, 141, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
0 | 1104 |
|
1105 |
x = 1; |
|
1106 |
y = 57; |
|
1107 |
sel = w->vscroll.pos; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1108 |
|
0 | 1109 |
// draw the first 3 details tabs |
1110 |
if (det_tab != 3) { |
|
1111 |
for(;;) { |
|
1112 |
if (--sel < 0 && sel >= -6) { |
|
1113 |
DrawTrainImage(v, x, y, 1, 0, INVALID_VEHICLE); |
|
1114 |
_train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + 30, y + 2); |
|
1115 |
y += 14; |
|
1116 |
} |
|
1117 |
if ( (v=v->next) == NULL) |
|
1118 |
return; |
|
1119 |
} |
|
1120 |
} |
|
1121 |
else { // draw total cargo tab |
|
1122 |
i = 0; |
|
1123 |
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); |
|
1124 |
do { |
|
1125 |
if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) { |
|
1126 |
y += 14; |
|
1127 |
// STR_013F_TOTAL_CAPACITY :{LTBLUE}- {CARGO} ({SHORTCARGO}) |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1128 |
SetDParam(0, i); // {CARGO} #1 |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1129 |
SetDParam(1, tot_cargo[i][0]); // {CARGO} #2 |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1130 |
SetDParam(2, i); // {SHORTCARGO} #1 |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1131 |
SetDParam(3, tot_cargo[i][1]); // {SHORTCARGO} #2 |
0 | 1132 |
DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0); |
1133 |
} |
|
1134 |
} while (++i != NUM_CARGO); |
|
1135 |
} |
|
1136 |
} |
|
1137 |
||
1138 |
static void TrainDetailsWndProc(Window *w, WindowEvent *e) |
|
1139 |
{ |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1140 |
switch (e->event) { |
0 | 1141 |
case WE_PAINT: |
1142 |
DrawTrainDetailsWindow(w); |
|
1143 |
break; |
|
1144 |
case WE_CLICK: { |
|
1145 |
int mod; |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1146 |
const Vehicle *v; |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1147 |
switch (e->click.widget) { |
0 | 1148 |
case 2: /* name train */ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1149 |
v = GetVehicle(w->window_number); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
1150 |
SetDParam(0, v->unitnumber); |
0 | 1151 |
ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number); |
1152 |
break; |
|
1153 |
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
|
1154 |
mod = _ctrl_pressed? 5 : 10; |
0 | 1155 |
goto do_change_service_int; |
1156 |
||
1157 |
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
|
1158 |
mod = _ctrl_pressed? -5 : -10; |
0 | 1159 |
do_change_service_int: |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1160 |
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
|
1161 |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1162 |
mod = GetServiceIntervalClamped(mod + v->service_interval); |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
1163 |
if (mod == v->service_interval) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1164 |
|
0 | 1165 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
1166 |
break; |
|
1167 |
/* details buttons*/ |
|
1168 |
case 9: // Cargo |
|
1169 |
case 10: // Information |
|
1170 |
case 11: // Capacities |
|
1171 |
case 12: // Total cargo |
|
1172 |
CLRBIT(w->disabled_state, 9); |
|
1173 |
CLRBIT(w->disabled_state, 10); |
|
1174 |
CLRBIT(w->disabled_state, 11); |
|
1175 |
CLRBIT(w->disabled_state, 12); |
|
1176 |
SETBIT(w->disabled_state, e->click.widget); |
|
1177 |
WP(w,traindetails_d).tab = e->click.widget - 9; |
|
1178 |
SetWindowDirty(w); |
|
1179 |
break; |
|
1180 |
} |
|
1181 |
} break; |
|
1182 |
||
1183 |
case WE_4: |
|
1184 |
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) |
|
1185 |
DeleteWindow(w); |
|
1186 |
break; |
|
1187 |
||
1188 |
case WE_ON_EDIT_TEXT: { |
|
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1189 |
if (e->edittext.str[0] != '\0') { |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1190 |
_cmd_text = e->edittext.str; |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1191 |
DoCommandP(0, w->window_number, 0, NULL, |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1192 |
CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); |
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1193 |
} |
0 | 1194 |
} break; |
1195 |
} |
|
1196 |
} |
|
1197 |
||
1198 |
static const Widget _train_details_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1199 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1200 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1201 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1202 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL}, |
893
f4698309dec7
(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
|
1203 |
{ WWT_MATRIX, RESIZE_NONE, 14, 0, 357, 56, 139, 0x601, STR_NULL}, |
f4698309dec7
(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
|
1204 |
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1205 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1206 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1207 |
{ WWT_PANEL, RESIZE_NONE, 14, 11, 369, 140, 151, 0x0, STR_NULL}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1208 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 92, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1209 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 93, 184, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1210 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 185, 277, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1211 |
{ 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
|
1212 |
{ WIDGETS_END}, |
0 | 1213 |
}; |
1214 |
||
1215 |
||
1216 |
static const WindowDesc _train_details_desc = { |
|
1217 |
-1,-1, 370, 164, |
|
1218 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
|
1219 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
1220 |
_train_details_widgets, |
|
1221 |
TrainDetailsWndProc |
|
1222 |
}; |
|
1223 |
||
1224 |
||
1225 |
void ShowTrainDetailsWindow(Vehicle *v) |
|
1226 |
{ |
|
1227 |
Window *w; |
|
1228 |
VehicleID veh = v->index; |
|
1229 |
||
1230 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
|
1231 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
1232 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1233 |
_alloc_wnd_parent_num = veh; |
0 | 1234 |
w = AllocateWindowDesc(&_train_details_desc); |
1235 |
||
1236 |
w->window_number = veh; |
|
1237 |
w->caption_color = v->owner; |
|
1238 |
w->vscroll.cap = 6; |
|
1239 |
WP(w,traindetails_d).tab = 0; |
|
1240 |
} |
|
1241 |
||
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1242 |
static const Widget _player_trains_widgets[] = { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1243 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1244 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1245 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1246 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1247 |
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1248 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1249 |
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL}, |
893
f4698309dec7
(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
|
1250 |
{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, |
f4698309dec7
(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
|
1251 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1252 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 156, 208, 219, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES}, |
893
f4698309dec7
(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
|
1253 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 157, 312, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP}, |
f4698309dec7
(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
|
1254 |
{ WWT_PANEL, RESIZE_RTB, 14, 313, 312, 208, 219, 0x0, STR_NULL}, |
f4698309dec7
(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
|
1255 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON}, |
588 | 1256 |
{ WIDGETS_END}, |
1257 |
}; |
|
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
|
1258 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1259 |
static const Widget _other_player_trains_widgets[] = { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1260 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1261 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1262 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1263 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1264 |
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1265 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1266 |
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL}, |
893
f4698309dec7
(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
|
1267 |
{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, |
f4698309dec7
(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
|
1268 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
f4698309dec7
(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
|
1269 |
{ WWT_PANEL, RESIZE_RTB, 14, 0, 312, 208, 219, 0x0, STR_NULL}, |
f4698309dec7
(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
|
1270 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON}, |
588 | 1271 |
{ WIDGETS_END}, |
1272 |
}; |
|
0 | 1273 |
|
1274 |
static void PlayerTrainsWndProc(Window *w, WindowEvent *e) |
|
1275 |
{ |
|
588 | 1276 |
int station = (int)w->window_number >> 16; |
1277 |
int owner = w->window_number & 0xff; |
|
1278 |
vehiclelist_d *vl = &WP(w, vehiclelist_d); |
|
1279 |
||
0 | 1280 |
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
|
1281 |
case WE_PAINT: { |
588 | 1282 |
int x = 2; |
1283 |
int y = PLY_WND_PRC__OFFSET_TOP_WIDGET; |
|
1284 |
int max; |
|
1285 |
int i; |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
1286 |
|
588 | 1287 |
BuildVehicleList(vl, VEH_Train, owner, station); |
1288 |
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
|
1289 |
|
588 | 1290 |
SetVScrollCount(w, vl->list_length); |
1291 |
||
1292 |
// disable 'Sort By' tooltip on Unsorted sorting criteria |
|
1293 |
if (vl->sort_type == SORT_BY_UNSORTED) |
|
757 | 1294 |
w->disabled_state |= (1 << 3); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1295 |
|
0 | 1296 |
/* draw the widgets */ |
1297 |
{ |
|
1962
8254df1b359b
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1938
diff
changeset
|
1298 |
const Player *p = GetPlayer(owner); |
588 | 1299 |
if (station == -1) { |
1300 |
/* Company Name -- (###) Trains */ |
|
1301 |
SetDParam(0, p->name_1); |
|
1302 |
SetDParam(1, p->name_2); |
|
1303 |
SetDParam(2, w->vscroll.count); |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1304 |
w->widget[1].unkA = STR_881B_TRAINS; |
588 | 1305 |
} else { |
1306 |
/* Station Name -- (###) Trains */ |
|
1294
4cdf0e76c093
(svn r1798) GetFoo(i)->index is per definition i, so replace the former with the latter
tron
parents:
1246
diff
changeset
|
1307 |
SetDParam(0, station); |
588 | 1308 |
SetDParam(1, w->vscroll.count); |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1309 |
w->widget[1].unkA = STR_SCHEDULED_TRAINS; |
588 | 1310 |
} |
0 | 1311 |
DrawWindowWidgets(w); |
1312 |
} |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
1313 |
/* draw sorting criteria string */ |
588 | 1314 |
DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10); |
1315 |
/* draw arrow pointing up/down for ascending/descending sorting */ |
|
1246
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1316 |
DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 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
|
1317 |
|
588 | 1318 |
max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length); |
1319 |
for (i = w->vscroll.pos; i < max; ++i) { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1320 |
Vehicle *v = GetVehicle(vl->sort_list[i].index); |
588 | 1321 |
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
|
1322 |
|
588 | 1323 |
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
|
1324 |
|
588 | 1325 |
DrawTrainImage( |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1326 |
v, x + 21, y + 6 + _traininfo_vehicle_pitch, w->hscroll.cap, 0, INVALID_VEHICLE); |
588 | 1327 |
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
|
1328 |
|
588 | 1329 |
SetDParam(0, v->unitnumber); |
1330
5d76a0522a11
(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
|
1330 |
if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) |
588 | 1331 |
str = STR_021F; |
1332 |
else |
|
1333 |
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; |
|
1334 |
DrawString(x, y + 2, str, 0); |
|
1335 |
||
1336 |
SetDParam(0, v->profit_this_year); |
|
1337 |
SetDParam(1, v->profit_last_year); |
|
1338 |
DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
|
1339 |
||
1340 |
if (v->string_id != STR_SV_TRAIN_NAME) { |
|
1341 |
SetDParam(0, v->string_id); |
|
1342 |
DrawString(x + 21, y, STR_01AB, 0); |
|
0 | 1343 |
} |
588 | 1344 |
|
1345 |
y += PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
|
0 | 1346 |
} |
588 | 1347 |
break; |
1348 |
} |
|
0 | 1349 |
|
1350 |
case WE_CLICK: { |
|
1351 |
switch(e->click.widget) { |
|
757 | 1352 |
case 3: /* Flip sorting method ascending/descending */ |
588 | 1353 |
vl->flags ^= VL_DESC; |
1354 |
vl->flags |= VL_RESORT; |
|
1246
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1355 |
_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
|
1356 |
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
|
1357 |
break; |
588 | 1358 |
|
757 | 1359 |
case 4: case 5:/* Select sorting criteria dropdown menu */ |
842 | 1360 |
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
|
1361 |
return; |
588 | 1362 |
|
757 | 1363 |
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
|
1364 |
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
|
1365 |
|
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
|
1366 |
if (id_v >= w->vscroll.cap) { return;} // click out of bounds |
0 | 1367 |
|
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
|
1368 |
id_v += w->vscroll.pos; |
0 | 1369 |
|
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
|
1370 |
{ |
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
|
1371 |
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
|
1372 |
|
588 | 1373 |
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
|
1374 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
914
diff
changeset
|
1375 |
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
|
1376 |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1019
diff
changeset
|
1377 |
assert(v->type == VEH_Train && v->subtype == TS_Front_Engine && 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
|
1378 |
|
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
|
1379 |
ShowTrainViewWindow(v); |
0 | 1380 |
} |
1381 |
} break; |
|
1382 |
||
757 | 1383 |
case 9: { /* Build new Vehicle */ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1384 |
TileIndex tile; |
0 | 1385 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1386 |
if (!IsWindowOfPrototype(w, _player_trains_widgets)) |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1387 |
break; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1388 |
|
0 | 1389 |
tile = _last_built_train_depot_tile; |
1390 |
do { |
|
1906
257d7487409a
(svn r2412) - Fix: [ 1214948 ] building vehicles without depot crashes game. (Chris Huebsch)
hackykid
parents:
1905
diff
changeset
|
1391 |
if (IsTileDepotType(tile, TRANSPORT_RAIL) && IsTileOwner(tile, _local_player)) { |
0 | 1392 |
ShowTrainDepotWindow(tile); |
1393 |
ShowBuildTrainWindow(tile); |
|
1394 |
return; |
|
1395 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
1396 |
|
0 | 1397 |
tile = TILE_MASK(tile + 1); |
1398 |
} 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
|
1399 |
|
0 | 1400 |
ShowBuildTrainWindow(0); |
1401 |
} break; |
|
842 | 1402 |
case 10: { |
886
3f8be7ff7b9c
(svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents:
878
diff
changeset
|
1403 |
if (!IsWindowOfPrototype(w, _player_trains_widgets)) |
3f8be7ff7b9c
(svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents:
878
diff
changeset
|
1404 |
break; |
3f8be7ff7b9c
(svn r1372) -Fix: fixed some GUI glitches introduced with resize-buttons
truelight
parents:
878
diff
changeset
|
1405 |
|
842 | 1406 |
ShowReplaceVehicleWindow(VEH_Train); |
1407 |
break; |
|
1408 |
} |
|
1409 |
||
0 | 1410 |
} |
1411 |
} break; |
|
1412 |
||
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 |
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ |
588 | 1414 |
if (vl->sort_type != e->dropdown.index) { |
1415 |
// value has changed -> resort |
|
1416 |
vl->flags |= VL_RESORT; |
|
1417 |
vl->sort_type = e->dropdown.index; |
|
1246
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1418 |
_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
|
1419 |
|
588 | 1420 |
// enable 'Sort By' if a sorter criteria is chosen |
1421 |
if (vl->sort_type != SORT_BY_UNSORTED) |
|
1246
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1422 |
CLRBIT(w->disabled_state, 3); |
588 | 1423 |
} |
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
|
1424 |
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
|
1425 |
break; |
588 | 1426 |
|
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
|
1427 |
case WE_CREATE: /* set up resort timer */ |
588 | 1428 |
vl->sort_list = NULL; |
1246
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1429 |
vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1)); |
eb66ff34348f
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1179
diff
changeset
|
1430 |
vl->sort_type = _sorting.train.criteria; |
588 | 1431 |
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
|
1432 |
break; |
588 | 1433 |
|
767 | 1434 |
case WE_DESTROY: |
1435 |
free(vl->sort_list); |
|
1436 |
break; |
|
1437 |
||
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
|
1438 |
case WE_TICK: /* resort the list every 20 seconds orso (10 days) */ |
588 | 1439 |
if (--vl->resort_timer == 0) { |
1440 |
DEBUG(misc, 1) ("Periodic resort trains list player %d station %d", |
|
1441 |
owner, station); |
|
1442 |
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
|
1443 |
vl->flags |= VL_RESORT; |
|
1444 |
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
|
1445 |
} |
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
|
1446 |
break; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1447 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1448 |
case WE_RESIZE: |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1449 |
/* Update the scroll + matrix */ |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1450 |
w->hscroll.cap += e->sizing.diff.x / 29; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1451 |
w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1452 |
w->widget[7].unkA = (w->vscroll.cap << 8) + 1; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1453 |
break; |
0 | 1454 |
} |
1455 |
} |
|
1456 |
||
1457 |
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
|
1458 |
-1, -1, 325, 220, |
0 | 1459 |
WC_TRAINS_LIST,0, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1460 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 1461 |
_player_trains_widgets, |
1462 |
PlayerTrainsWndProc |
|
1463 |
}; |
|
1464 |
||
1465 |
static const WindowDesc _other_player_trains_desc = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1466 |
-1, -1, 325, 220, |
0 | 1467 |
WC_TRAINS_LIST,0, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1468 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 1469 |
_other_player_trains_widgets, |
1470 |
PlayerTrainsWndProc |
|
1471 |
}; |
|
1472 |
||
588 | 1473 |
void ShowPlayerTrains(int player, int station) |
0 | 1474 |
{ |
1475 |
Window *w; |
|
1476 |
||
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
|
1477 |
if (player == _local_player) { |
588 | 1478 |
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
|
1479 |
} else { |
588 | 1480 |
w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player); |
0 | 1481 |
} |
1482 |
if (w) { |
|
1402
033a3f3e05e0
(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
|
1483 |
w->caption_color = player; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1484 |
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
|
1485 |
w->vscroll.cap = 7; // maximum number of vehicles shown |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1486 |
w->widget[7].unkA = (w->vscroll.cap << 8) + 1; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1487 |
w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1488 |
w->resize.step_width = 29; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
1489 |
w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */ |
0 | 1490 |
} |
1491 |
} |