author | Darkvater |
Sat, 18 Nov 2006 17:04:44 +0000 | |
changeset 5125 | d1331d6dbdcb |
parent 5078 | b9fb462c82f2 |
child 5198 | 7046e5b0b5bc |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
3959 | 7 |
#include "roadveh.h" |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
8 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
374
diff
changeset
|
9 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
671
diff
changeset
|
10 |
#include "map.h" |
0 | 11 |
#include "window.h" |
12 |
#include "gui.h" |
|
13 |
#include "gfx.h" |
|
14 |
#include "vehicle.h" |
|
15 |
#include "viewport.h" |
|
16 |
#include "station.h" |
|
17 |
#include "command.h" |
|
18 |
#include "player.h" |
|
19 |
#include "engine.h" |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
20 |
#include "depot.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2113
diff
changeset
|
21 |
#include "vehicle_gui.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2958
diff
changeset
|
22 |
#include "newgrf_engine.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4243
diff
changeset
|
23 |
#include "date.h" |
0 | 24 |
|
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
|
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 |
* Draw the purchase info details of road vehicle 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
|
27 |
* @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
|
28 |
* @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
|
29 |
*/ |
4930
708801d486c6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4896
diff
changeset
|
30 |
void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number) |
842 | 31 |
{ |
32 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine_number); |
|
4171 | 33 |
const Engine *e = GetEngine(engine_number); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
34 |
bool refittable = (_engine_info[engine_number].refit_mask != 0); |
842 | 35 |
YearMonthDay ymd; |
4288
393de75451b1
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4286
diff
changeset
|
36 |
ConvertDateToYMD(e->intro_date, &ymd); |
842 | 37 |
|
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
|
38 |
/* Purchase cost - Max speed */ |
842 | 39 |
SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5); |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3431
diff
changeset
|
40 |
SetDParam(1, rvi->max_speed / 2); |
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
|
41 |
DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 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
|
42 |
y += 10; |
842 | 43 |
|
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
|
44 |
/* 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
|
45 |
SetDParam(0, rvi->running_cost * _price.roadveh_running >> 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
|
46 |
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
|
47 |
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
|
48 |
|
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 |
/* Cargo type + capacity */ |
4896
f86350aaaaa5
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4793
diff
changeset
|
50 |
SetDParam(0, 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
|
51 |
SetDParam(1, rvi->capacity); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
52 |
SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); |
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
|
53 |
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
|
54 |
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
|
55 |
|
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
56 |
/* Design date - Life length */ |
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4288
diff
changeset
|
57 |
SetDParam(0, ymd.year); |
1907
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
|
61bafb476865
(svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents:
1906
diff
changeset
|
62 |
/* 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
|
63 |
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
|
64 |
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
|
65 |
y += 10; |
4243
b0361faa4dfd
(svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents:
4171
diff
changeset
|
66 |
|
b0361faa4dfd
(svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents:
4171
diff
changeset
|
67 |
/* Additional text from NewGRF */ |
4930
708801d486c6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4896
diff
changeset
|
68 |
y += ShowAdditionalText(x, y, w, engine_number); |
4932
4bf213d0ed53
(svn r6912) - Feature: Show a list of cargo types that a vehicle is refittable to in the purchase information window. (mart3p)
peter1138
parents:
4931
diff
changeset
|
69 |
y += ShowRefitOptionsList(x, y, w, engine_number); |
842 | 70 |
} |
71 |
||
4442
9f8bb348d58f
(svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents:
4434
diff
changeset
|
72 |
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection) |
0 | 73 |
{ |
3049
d6109b5fd55d
(svn r3631) - 2cc: Remove use of some temporary variables and perform minor optimization in the form of the ternary operator.
peter1138
parents:
3040
diff
changeset
|
74 |
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3049
diff
changeset
|
75 |
DrawSprite(GetRoadVehImage(v, DIR_W) | pal, x + 14, y + 6); |
0 | 76 |
|
77 |
if (v->index == selection) { |
|
2639 | 78 |
DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); |
0 | 79 |
} |
80 |
} |
|
81 |
||
82 |
static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) |
|
83 |
{ |
|
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:
1485
diff
changeset
|
84 |
switch (e->event) { |
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:
1485
diff
changeset
|
85 |
case WE_PAINT: { |
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:
1485
diff
changeset
|
86 |
const Vehicle *v = GetVehicle(w->window_number); |
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:
1485
diff
changeset
|
87 |
StringID str; |
0 | 88 |
|
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
89 |
SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4012
diff
changeset
|
90 |
// disable service-scroller when interval is set to disabled |
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
91 |
SetWindowWidgetDisabledState(w, 5, !_patches.servint_roadveh); |
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
92 |
SetWindowWidgetDisabledState(w, 6, !_patches.servint_roadveh); |
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:
10
diff
changeset
|
93 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
94 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
95 |
SetDParam(1, v->unitnumber); |
0 | 96 |
DrawWindowWidgets(w); |
97 |
||
98 |
/* Draw running cost */ |
|
99 |
{ |
|
100 |
int year = v->age / 366; |
|
101 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
102 |
SetDParam(1, year); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
103 |
|
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2252
diff
changeset
|
104 |
SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
105 |
SetDParam(2, v->max_age / 366); |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
106 |
SetDParam(3, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running >> 8); |
0 | 107 |
DrawString(2, 15, STR_900D_AGE_RUNNING_COST_YR, 0); |
108 |
} |
|
109 |
||
110 |
/* Draw max speed */ |
|
111 |
{ |
|
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3431
diff
changeset
|
112 |
SetDParam(0, v->max_speed / 2); |
0 | 113 |
DrawString(2, 25, STR_900E_MAX_SPEED, 0); |
114 |
} |
|
115 |
||
116 |
/* Draw profit */ |
|
117 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
118 |
SetDParam(0, v->profit_this_year); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
119 |
SetDParam(1, v->profit_last_year); |
0 | 120 |
DrawString(2, 35, STR_900F_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
121 |
} |
|
122 |
||
123 |
/* Draw breakdown & reliability */ |
|
124 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
125 |
SetDParam(0, v->reliability * 100 >> 16); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
126 |
SetDParam(1, v->breakdowns_since_last_service); |
0 | 127 |
DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0); |
128 |
} |
|
129 |
||
130 |
/* Draw service interval text */ |
|
131 |
{ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
132 |
SetDParam(0, v->service_interval); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
133 |
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:
10
diff
changeset
|
134 |
DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
0 | 135 |
} |
136 |
||
137 |
DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE); |
|
138 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
139 |
SetDParam(0, GetCustomEngineName(v->engine_type)); |
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4299
diff
changeset
|
140 |
SetDParam(1, v->build_year); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
141 |
SetDParam(2, v->value); |
0 | 142 |
DrawString(34, 57, STR_9011_BUILT_VALUE, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
143 |
|
4896
f86350aaaaa5
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4793
diff
changeset
|
144 |
SetDParam(0, v->cargo_type); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
145 |
SetDParam(1, v->cargo_cap); |
0 | 146 |
DrawString(34, 67, STR_9012_CAPACITY, 0); |
147 |
||
148 |
str = STR_8812_EMPTY; |
|
149 |
if (v->cargo_count != 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
150 |
SetDParam(0, v->cargo_type); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
151 |
SetDParam(1, v->cargo_count); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
152 |
SetDParam(2, v->cargo_source); |
0 | 153 |
str = STR_8813_FROM; |
154 |
} |
|
155 |
DrawString(34, 78, str, 0); |
|
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:
1485
diff
changeset
|
156 |
} break; |
0 | 157 |
|
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:
1485
diff
changeset
|
158 |
case WE_CLICK: { |
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:
1485
diff
changeset
|
159 |
int mod; |
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:
1485
diff
changeset
|
160 |
const Vehicle *v; |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
161 |
switch (e->we.click.widget) { |
0 | 162 |
case 2: /* rename */ |
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:
1485
diff
changeset
|
163 |
v = GetVehicle(w->window_number); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
164 |
SetDParam(0, v->unitnumber); |
4299
91f5d2bedcff
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents:
4293
diff
changeset
|
165 |
ShowQueryString(v->string_id, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL); |
0 | 166 |
break; |
167 |
||
168 |
case 5: /* increase int */ |
|
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:
10
diff
changeset
|
169 |
mod = _ctrl_pressed? 5 : 10; |
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:
1485
diff
changeset
|
170 |
goto do_change_service_int; |
0 | 171 |
case 6: /* decrease int */ |
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:
10
diff
changeset
|
172 |
mod = _ctrl_pressed? -5 : -10; |
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:
1485
diff
changeset
|
173 |
do_change_service_int: |
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:
1485
diff
changeset
|
174 |
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:
10
diff
changeset
|
175 |
|
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:
1485
diff
changeset
|
176 |
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:
1485
diff
changeset
|
177 |
if (mod == v->service_interval) return; |
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:
10
diff
changeset
|
178 |
|
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2806
diff
changeset
|
179 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
0 | 180 |
break; |
181 |
} |
|
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:
1485
diff
changeset
|
182 |
} break; |
0 | 183 |
|
184 |
case WE_ON_EDIT_TEXT: { |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
185 |
if (e->we.edittext.str[0] != '\0') { |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
186 |
_cmd_text = e->we.edittext.str; |
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1790
diff
changeset
|
187 |
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:
1790
diff
changeset
|
188 |
CMD_NAME_VEHICLE | CMD_MSG(STR_902D_CAN_T_NAME_ROAD_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:
1790
diff
changeset
|
189 |
} |
0 | 190 |
} break; |
191 |
||
192 |
} |
|
193 |
} |
|
194 |
||
195 |
static const Widget _roadveh_details_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
196 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
197 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 339, 0, 13, STR_900C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
198 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 340, 379, 0, 13, STR_01AA_NAME, STR_902E_NAME_ROAD_VEHICLE}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4937
diff
changeset
|
199 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 379, 14, 55, 0x0, STR_NULL}, |
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4937
diff
changeset
|
200 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 379, 56, 88, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
201 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 89, 94, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
202 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 95, 100, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4937
diff
changeset
|
203 |
{ WWT_PANEL, RESIZE_NONE, 14, 11, 379, 89, 100, 0x0, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
174
diff
changeset
|
204 |
{ WIDGETS_END}, |
0 | 205 |
}; |
206 |
||
207 |
static const WindowDesc _roadveh_details_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
208 |
WDP_AUTO, WDP_AUTO, 380, 101, |
0 | 209 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
210 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
211 |
_roadveh_details_widgets, |
|
212 |
RoadVehDetailsWndProc |
|
213 |
}; |
|
214 |
||
4171 | 215 |
static void ShowRoadVehDetailsWindow(const Vehicle *v) |
0 | 216 |
{ |
217 |
Window *w; |
|
218 |
VehicleID veh = v->index; |
|
2639 | 219 |
|
0 | 220 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
221 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
5071
e28106dfcb6f
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5070
diff
changeset
|
222 |
|
e28106dfcb6f
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5070
diff
changeset
|
223 |
w = AllocateWindowDescFront(&_roadveh_details_desc, veh); |
0 | 224 |
w->caption_color = v->owner; |
225 |
} |
|
226 |
||
3887
ece644bbf459
(svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents:
3884
diff
changeset
|
227 |
void CcCloneRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) |
2244 | 228 |
{ |
3948
a09379beffd5
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3887
diff
changeset
|
229 |
if (success) ShowRoadVehViewWindow(GetVehicle(_new_vehicle_id)); |
2244 | 230 |
} |
231 |
||
0 | 232 |
static void RoadVehViewWndProc(Window *w, WindowEvent *e) |
233 |
{ |
|
2952 | 234 |
switch (e->event) { |
0 | 235 |
case WE_PAINT: { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
893
diff
changeset
|
236 |
Vehicle *v = GetVehicle(w->window_number); |
0 | 237 |
StringID str; |
5078
b9fb462c82f2
(svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents:
5071
diff
changeset
|
238 |
bool is_localplayer = v->owner == _local_player; |
0 | 239 |
|
5078
b9fb462c82f2
(svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents:
5071
diff
changeset
|
240 |
SetWindowWidgetDisabledState(w, 7, !is_localplayer); |
b9fb462c82f2
(svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents:
5071
diff
changeset
|
241 |
SetWindowWidgetDisabledState(w, 8, !is_localplayer); |
b9fb462c82f2
(svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents:
5071
diff
changeset
|
242 |
SetWindowWidgetDisabledState(w, 11, !is_localplayer); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
243 |
/* Disable refit button if vehicle not refittable */ |
5078
b9fb462c82f2
(svn r7142) -Fix: disable clone button in vehicle view for not owned vehicles (was already done for trains)
glx
parents:
5071
diff
changeset
|
244 |
SetWindowWidgetDisabledState(w, 12, !is_localplayer || |
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
245 |
_engine_info[v->engine_type].refit_mask == 0); |
0 | 246 |
|
247 |
/* draw widgets & caption */ |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
248 |
SetDParam(0, v->string_id); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
249 |
SetDParam(1, v->unitnumber); |
0 | 250 |
DrawWindowWidgets(w); |
251 |
||
252 |
if (v->u.road.crashed_ctr != 0) { |
|
253 |
str = STR_8863_CRASHED; |
|
254 |
} else if (v->breakdown_ctr == 1) { |
|
255 |
str = STR_885C_BROKEN_DOWN; |
|
256 |
} else if (v->vehstatus & VS_STOPPED) { |
|
257 |
str = STR_8861_STOPPED; |
|
258 |
} else { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
259 |
switch (v->current_order.type) { |
0 | 260 |
case OT_GOTO_STATION: { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4524
diff
changeset
|
261 |
SetDParam(0, v->current_order.dest); |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3431
diff
changeset
|
262 |
SetDParam(1, v->cur_speed / 2); |
0 | 263 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
264 |
} break; |
|
265 |
||
266 |
case OT_GOTO_DEPOT: { |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4524
diff
changeset
|
267 |
Depot *depot = GetDepot(v->current_order.dest); |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
268 |
SetDParam(0, depot->town_index); |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3431
diff
changeset
|
269 |
SetDParam(1, v->cur_speed / 2); |
4633
cf6c2f173030
(svn r6497) -Fix r6165: Vehicles heading for depots when their orders contained "service in depot" displayed the stopping in depot string
bjarni
parents:
4547
diff
changeset
|
270 |
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { |
4412
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
271 |
str = STR_HEADING_FOR_ROAD_DEPOT + _patches.vehicle_speed; |
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
272 |
} else { |
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
273 |
str = STR_HEADING_FOR_ROAD_DEPOT_SERVICE + _patches.vehicle_speed; |
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4408
diff
changeset
|
274 |
} |
0 | 275 |
} break; |
276 |
||
277 |
case OT_LOADING: |
|
278 |
case OT_LEAVESTATION: |
|
279 |
str = STR_882F_LOADING_UNLOADING; |
|
280 |
break; |
|
281 |
||
282 |
default: |
|
283 |
if (v->num_orders == 0) { |
|
284 |
str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3431
diff
changeset
|
285 |
SetDParam(0, v->cur_speed / 2); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4012
diff
changeset
|
286 |
} else { |
0 | 287 |
str = STR_EMPTY; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4012
diff
changeset
|
288 |
} |
0 | 289 |
break; |
290 |
} |
|
291 |
} |
|
292 |
||
2103
a2b3106d33d5
(svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents:
2084
diff
changeset
|
293 |
/* draw the flag plus orders */ |
2517
6e3832ddd0f6
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2498
diff
changeset
|
294 |
DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1); |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2103
diff
changeset
|
295 |
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0); |
0 | 296 |
DrawWindowViewport(w); |
297 |
} break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
298 |
|
0 | 299 |
case WE_CLICK: { |
4171 | 300 |
const Vehicle *v = GetVehicle(w->window_number); |
0 | 301 |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
302 |
switch (e->we.click.widget) { |
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
|
303 |
case 5: /* start stop */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
304 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE)); |
0 | 305 |
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
|
306 |
case 6: /* center main view */ |
0 | 307 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
308 |
break; |
|
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
309 |
case 7: /* goto depot */ |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4473
diff
changeset
|
310 |
DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT)); |
0 | 311 |
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
|
312 |
case 8: /* turn around */ |
0 | 313 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_TURN_ROADVEH | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); |
314 |
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
|
315 |
case 9: /* show orders */ |
0 | 316 |
ShowOrdersWindow(v); |
317 |
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
|
318 |
case 10: /* show details */ |
0 | 319 |
ShowRoadVehDetailsWindow(v); |
320 |
break; |
|
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
321 |
case 11: /* clone vehicle */ |
2244 | 322 |
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh, CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
323 |
break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
324 |
case 12: /* Refit vehicle */ |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4709
diff
changeset
|
325 |
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
326 |
break; |
0 | 327 |
} |
328 |
} break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
329 |
|
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1330
diff
changeset
|
330 |
case WE_RESIZE: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
331 |
w->viewport->width += e->we.sizing.diff.x; |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
332 |
w->viewport->height += e->we.sizing.diff.y; |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
333 |
w->viewport->virtual_width += e->we.sizing.diff.x; |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
334 |
w->viewport->virtual_height += e->we.sizing.diff.y; |
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1330
diff
changeset
|
335 |
break; |
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1330
diff
changeset
|
336 |
|
0 | 337 |
case WE_DESTROY: |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3960
diff
changeset
|
338 |
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); |
0 | 339 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
340 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
341 |
break; |
2244 | 342 |
|
4702
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
343 |
case WE_MOUSELOOP: { |
4171 | 344 |
const Vehicle *v = GetVehicle(w->window_number); |
4702
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
345 |
bool rv_stopped = IsRoadVehInDepotStopped(v); |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3990
diff
changeset
|
346 |
|
4702
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
347 |
/* Widget 7 (send to depot) must be hidden if the truck/bus is already stopped in depot. |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
348 |
* Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped. |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
349 |
* This sytem allows to have two buttons, on top of each other. |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
350 |
* The same system applies to widget 8 and 12, force turn around and refit. */ |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
351 |
if (rv_stopped != IsWindowWidgetHidden(w, 7) || rv_stopped == IsWindowWidgetHidden(w, 11)) { |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
352 |
SetWindowWidgetHiddenState(w, 7, rv_stopped); // send to depot |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
353 |
SetWindowWidgetHiddenState(w, 8, rv_stopped); // force turn around |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
354 |
SetWindowWidgetHiddenState(w, 11, !rv_stopped); // clone |
c79e9d9f27b3
(svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents:
4668
diff
changeset
|
355 |
SetWindowWidgetHiddenState(w, 12, !rv_stopped); // refit |
2244 | 356 |
SetWindowDirty(w); |
357 |
} |
|
358 |
} |
|
0 | 359 |
} |
360 |
} |
|
361 |
||
362 |
static const Widget _roadveh_view_widgets[] = { |
|
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
363 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, |
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
364 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_9002, STR_018C_WINDOW_TITLE_DRAG_THIS }, |
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
365 |
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, |
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
366 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 103, 0x0, STR_NULL }, |
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
367 |
{ WWT_INSET, RESIZE_RB, 14, 2, 229, 16, 101, 0x0, STR_NULL }, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4937
diff
changeset
|
368 |
{ WWT_PUSHBTN, RESIZE_RTB, 14, 0, 237, 104, 115, 0x0, STR_901C_CURRENT_VEHICLE_ACTION }, |
4937
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
369 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, SPR_CENTRE_VIEW_VEHICLE, STR_901E_CENTER_MAIN_VIEW_ON_VEHICLE }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
370 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_SEND_ROADVEH_TODEPOT,STR_901F_SEND_VEHICLE_TO_DEPOT }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
371 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_FORCE_VEHICLE_TURN, STR_9020_FORCE_VEHICLE_TO_TURN_AROUND }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
372 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_SHOW_ORDERS, STR_901D_SHOW_VEHICLE_S_ORDERS }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
373 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, SPR_SHOW_VEHICLE_DETAILS,STR_9021_SHOW_ROAD_VEHICLE_DETAILS }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
374 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_ROADVEH, STR_CLONE_ROAD_VEHICLE_INFO }, |
8cfdd86fd709
(svn r6924) -Codechange: Give the last (in the widget arrays at least) sprites meaningful names.
Darkvater
parents:
4932
diff
changeset
|
375 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_REFIT_VEHICLE, STR_REFIT_ROAD_VEHICLE_TO_CARRY }, |
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
376 |
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 104, 103, 0x0, STR_NULL }, |
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
377 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 104, 115, 0x0, STR_NULL }, |
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1330
diff
changeset
|
378 |
{ WIDGETS_END } |
0 | 379 |
}; |
380 |
||
381 |
static const WindowDesc _roadveh_view_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
382 |
WDP_AUTO, WDP_AUTO, 250, 116, |
0 | 383 |
WC_VEHICLE_VIEW,0, |
1485
34545d21c656
(svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents:
1330
diff
changeset
|
384 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
0 | 385 |
_roadveh_view_widgets, |
386 |
RoadVehViewWndProc, |
|
387 |
}; |
|
388 |
||
4171 | 389 |
void ShowRoadVehViewWindow(const Vehicle *v) |
0 | 390 |
{ |
4171 | 391 |
Window *w = AllocateWindowDescFront(&_roadveh_view_desc, v->index); |
0 | 392 |
|
2561
233dafd7cf6c
(svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents:
2549
diff
changeset
|
393 |
if (w != NULL) { |
0 | 394 |
w->caption_color = v->owner; |
395 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0); |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
||
400 |
static void DrawNewRoadVehWindow(Window *w) |
|
401 |
{ |
|
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
402 |
EngineID selected_id; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
403 |
EngineID e; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
404 |
uint count; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
405 |
int pos; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
406 |
int sel; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
407 |
int y; |
0 | 408 |
|
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
409 |
SetWindowWidgetDisabledState(w, 5, w->window_number == 0); |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
410 |
|
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
411 |
count = 0; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
412 |
for (e = ROAD_ENGINES_INDEX; e < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; e++) { |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
413 |
if (HASBIT(GetEngine(e)->player_avail, _local_player)) count++; |
0 | 414 |
} |
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
415 |
SetVScrollCount(w, count); |
0 | 416 |
|
417 |
DrawWindowWidgets(w); |
|
418 |
||
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
419 |
y = 15; |
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
420 |
sel = WP(w,buildvehicle_d).sel_index; |
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
421 |
pos = w->vscroll.pos; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
422 |
selected_id = INVALID_ENGINE; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
423 |
for (e = ROAD_ENGINES_INDEX; e < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; e++) { |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
424 |
if (!HASBIT(GetEngine(e)->player_avail, _local_player)) continue; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
425 |
if (sel == 0) selected_id = e; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
426 |
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
427 |
DrawString(60, y + 2, GetCustomEngineName(e), sel == 0 ? 0xC : 0x10); |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
428 |
DrawRoadVehEngine(30, y + 6, e, GetEnginePalette(e, _local_player)); |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
429 |
y += 14; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
430 |
} |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
431 |
sel--; |
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
432 |
} |
0 | 433 |
|
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
434 |
WP(w,buildvehicle_d).sel_engine = selected_id; |
4473
1acd836dcfe7
(svn r6258) Reduce the number of induction variables and inner scopes for clarity
tron
parents:
4456
diff
changeset
|
435 |
if (selected_id != INVALID_ENGINE) { |
4930
708801d486c6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4896
diff
changeset
|
436 |
const Widget *wi = &w->widget[4]; |
708801d486c6
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents:
4896
diff
changeset
|
437 |
DrawRoadVehPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); |
0 | 438 |
} |
439 |
} |
|
440 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
441 |
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 442 |
{ |
4171 | 443 |
const Vehicle *v; |
0 | 444 |
|
445 |
if (!success) return; |
|
446 |
||
3948
a09379beffd5
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3887
diff
changeset
|
447 |
v = GetVehicle(_new_vehicle_id); |
0 | 448 |
if (v->tile == _backup_orders_tile) { |
449 |
_backup_orders_tile = 0; |
|
450 |
RestoreVehicleOrders(v, _backup_orders_data); |
|
451 |
} |
|
452 |
ShowRoadVehViewWindow(v); |
|
453 |
} |
|
454 |
||
455 |
static void NewRoadVehWndProc(Window *w, WindowEvent *e) |
|
456 |
{ |
|
2639 | 457 |
switch (e->event) { |
4793
61f36389399f
(svn r6715) -Fix r6714: roadvehicle and ship building windows are now also marked dirty when getting a WE_INVALIDATE_DATA event
bjarni
parents:
4790
diff
changeset
|
458 |
case WE_INVALIDATE_DATA: |
61f36389399f
(svn r6715) -Fix r6714: roadvehicle and ship building windows are now also marked dirty when getting a WE_INVALIDATE_DATA event
bjarni
parents:
4790
diff
changeset
|
459 |
SetWindowDirty(w); |
61f36389399f
(svn r6715) -Fix r6714: roadvehicle and ship building windows are now also marked dirty when getting a WE_INVALIDATE_DATA event
bjarni
parents:
4790
diff
changeset
|
460 |
break; |
61f36389399f
(svn r6715) -Fix r6714: roadvehicle and ship building windows are now also marked dirty when getting a WE_INVALIDATE_DATA event
bjarni
parents:
4790
diff
changeset
|
461 |
|
0 | 462 |
case WE_PAINT: |
463 |
DrawNewRoadVehWindow(w); |
|
464 |
break; |
|
465 |
||
466 |
case WE_CLICK: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
467 |
switch (e->we.click.widget) { |
0 | 468 |
case 2: { /* listbox */ |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
469 |
uint i = (e->we.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
|
470 |
if (i < w->vscroll.cap) { |
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
471 |
WP(w,buildvehicle_d).sel_index = i + w->vscroll.pos; |
0 | 472 |
SetWindowDirty(w); |
473 |
} |
|
474 |
} break; |
|
475 |
||
476 |
case 5: { /* build */ |
|
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
477 |
EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2477
diff
changeset
|
478 |
if (sel_eng != INVALID_ENGINE) |
0 | 479 |
DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)); |
480 |
} break; |
|
481 |
||
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
|
482 |
case 6: { /* rename */ |
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
483 |
EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2477
diff
changeset
|
484 |
if (sel_eng != INVALID_ENGINE) { |
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
485 |
WP(w,buildvehicle_d).rename_engine = sel_eng; |
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
|
486 |
ShowQueryString(GetCustomEngineName(sel_eng), |
4299
91f5d2bedcff
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents:
4293
diff
changeset
|
487 |
STR_9036_RENAME_ROAD_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL); |
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
|
488 |
} |
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
|
489 |
} break; |
0 | 490 |
} |
491 |
break; |
|
492 |
||
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2517
diff
changeset
|
493 |
case WE_ON_EDIT_TEXT: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
494 |
if (e->we.edittext.str[0] != '\0') { |
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
495 |
_cmd_text = e->we.edittext.str; |
4790
69e0d03632c9
(svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents:
4712
diff
changeset
|
496 |
DoCommandP(0, WP(w, buildvehicle_d).rename_engine, 0, NULL, |
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:
1790
diff
changeset
|
497 |
CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_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:
1790
diff
changeset
|
498 |
} |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2517
diff
changeset
|
499 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
500 |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
501 |
case WE_RESIZE: { |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
502 |
if (e->we.sizing.diff.y == 0) break; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
503 |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4633
diff
changeset
|
504 |
w->vscroll.cap += e->we.sizing.diff.y / 14; |
4547
d37c2d172ad4
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4541
diff
changeset
|
505 |
w->widget[2].data = (w->vscroll.cap << 8) + 1; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
506 |
} break; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
507 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
508 |
} |
0 | 509 |
} |
510 |
||
511 |
static const Widget _new_road_veh_widgets[] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
512 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
513 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 247, 0, 13, STR_9006_NEW_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
514 |
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 235, 14, 125, 0x801, STR_9026_ROAD_VEHICLE_SELECTION}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
515 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 236, 247, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
4931
c25335d7e99c
(svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents:
4930
diff
changeset
|
516 |
{ WWT_PANEL, RESIZE_TB, 14, 0, 247, 126, 217, 0x0, STR_NULL}, |
c25335d7e99c
(svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents:
4930
diff
changeset
|
517 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 117, 218, 229, STR_9007_BUILD_VEHICLE, STR_9027_BUILD_THE_HIGHLIGHTED_ROAD}, |
c25335d7e99c
(svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents:
4930
diff
changeset
|
518 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 118, 235, 218, 229, STR_9034_RENAME, STR_9035_RENAME_ROAD_VEHICLE_TYPE}, |
c25335d7e99c
(svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents:
4930
diff
changeset
|
519 |
{ WWT_RESIZEBOX, RESIZE_TB, 14, 236, 247, 218, 229, 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
|
520 |
{ WIDGETS_END}, |
0 | 521 |
}; |
522 |
||
523 |
static const WindowDesc _new_road_veh_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4939
diff
changeset
|
524 |
WDP_AUTO, WDP_AUTO, 248, 230, |
0 | 525 |
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
|
526 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
0 | 527 |
_new_road_veh_widgets, |
528 |
NewRoadVehWndProc |
|
529 |
}; |
|
530 |
||
4442
9f8bb348d58f
(svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents:
4434
diff
changeset
|
531 |
void ShowBuildRoadVehWindow(TileIndex tile) |
0 | 532 |
{ |
533 |
Window *w; |
|
534 |
||
535 |
DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
536 |
||
5125
d1331d6dbdcb
(svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents:
5078
diff
changeset
|
537 |
w = AllocateWindowDescFront(&_new_road_veh_desc, tile); |
0 | 538 |
w->vscroll.cap = 8; |
4547
d37c2d172ad4
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4541
diff
changeset
|
539 |
w->widget[2].data = (w->vscroll.cap << 8) + 1; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
540 |
|
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
842
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
|
0 | 544 |
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
|
545 |
w->caption_color = GetTileOwner(tile); |
0 | 546 |
} else { |
547 |
w->caption_color = _local_player; |
|
548 |
} |
|
549 |
} |
|
550 |
||
4709
a81ab800c25b
(svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents:
4702
diff
changeset
|
551 |