9 #include "roadveh.h" |
9 #include "roadveh.h" |
10 #include "table/sprites.h" |
10 #include "table/sprites.h" |
11 #include "table/strings.h" |
11 #include "table/strings.h" |
12 #include "window.h" |
12 #include "window.h" |
13 #include "gui.h" |
13 #include "gui.h" |
|
14 #include "strings.h" |
14 #include "vehicle.h" |
15 #include "vehicle.h" |
15 #include "viewport.h" |
16 #include "viewport.h" |
16 #include "command.h" |
17 #include "command.h" |
17 #include "depot.h" |
18 #include "depot.h" |
18 #include "vehicle_gui.h" |
19 #include "vehicle_gui.h" |
19 #include "newgrf_engine.h" |
20 #include "newgrf_engine.h" |
20 |
21 |
21 void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection) |
22 static inline int RoadVehLengthToPixels(int length) |
22 { |
23 { |
23 SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
24 return (length * 28) / 8; |
24 DrawSprite(GetRoadVehImage(v, DIR_W), pal, x + 14, y + 6); |
25 } |
25 |
26 |
26 if (v->index == selection) { |
27 void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selection) |
27 DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); |
28 { |
28 } |
29 int dx = 0; |
|
30 |
|
31 /* Road vehicle lengths are measured in eighths of the standard length, so |
|
32 * count is the number of standard vehicles that should be drawn. If it is |
|
33 * 0, we draw enough vehicles for 10 standard vehicle lengths. */ |
|
34 int max_length = (count == 0) ? 80 : count * 8; |
|
35 |
|
36 do { |
|
37 int length = v->u.road.cached_veh_length; |
|
38 |
|
39 if (dx + length > 0 && dx <= max_length) { |
|
40 SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
|
41 DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6); |
|
42 |
|
43 if (v->index == selection) { |
|
44 DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); |
|
45 } |
|
46 } |
|
47 |
|
48 dx += length; |
|
49 v = v->next; |
|
50 } while (v != NULL && dx < max_length); |
29 } |
51 } |
30 |
52 |
31 static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) |
53 static void RoadVehDetailsWndProc(Window *w, WindowEvent *e) |
32 { |
54 { |
33 switch (e->event) { |
55 switch (e->event) { |
|
56 case WE_CREATE: { |
|
57 const Vehicle *v = GetVehicle(w->window_number); |
|
58 |
|
59 if (!RoadVehHasArticPart(v)) break; |
|
60 |
|
61 /* Draw the text under the vehicle instead of next to it, minus the |
|
62 * height already allocated for the cargo of the first vehicle. */ |
|
63 uint height_extension = 15 - 11; |
|
64 |
|
65 /* Add space for the cargo amount for each part. */ |
|
66 do { |
|
67 height_extension += 11; |
|
68 } while ((v = v->next) != NULL); |
|
69 |
|
70 ResizeWindow(w, 0, height_extension); |
|
71 } break; |
|
72 |
34 case WE_PAINT: { |
73 case WE_PAINT: { |
35 const Vehicle *v = GetVehicle(w->window_number); |
74 const Vehicle *v = GetVehicle(w->window_number); |
36 StringID str; |
75 StringID str; |
|
76 uint y_offset = RoadVehHasArticPart(v) ? 15 :0; |
37 |
77 |
38 SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); |
78 SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); |
39 /* disable service-scroller when interval is set to disabled */ |
79 /* disable service-scroller when interval is set to disabled */ |
40 SetWindowWidgetDisabledState(w, 5, !_patches.servint_roadveh); |
80 SetWindowWidgetDisabledState(w, 5, !_patches.servint_roadveh); |
41 SetWindowWidgetDisabledState(w, 6, !_patches.servint_roadveh); |
81 SetWindowWidgetDisabledState(w, 6, !_patches.servint_roadveh); |
42 |
82 |
43 SetDParam(0, v->string_id); |
83 SetDParam(0, v->index); |
44 SetDParam(1, v->unitnumber); |
|
45 DrawWindowWidgets(w); |
84 DrawWindowWidgets(w); |
46 |
85 |
47 /* Draw running cost */ |
86 /* Draw running cost */ |
48 { |
87 { |
49 int year = v->age / 366; |
88 int year = v->age / 366; |
74 SetDParam(0, v->reliability * 100 >> 16); |
113 SetDParam(0, v->reliability * 100 >> 16); |
75 SetDParam(1, v->breakdowns_since_last_service); |
114 SetDParam(1, v->breakdowns_since_last_service); |
76 DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0); |
115 DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0); |
77 } |
116 } |
78 |
117 |
|
118 DrawRoadVehImage(v, 3, 57, 0, INVALID_VEHICLE); |
|
119 |
|
120 SetDParam(0, v->engine_type); |
|
121 SetDParam(1, v->build_year); |
|
122 SetDParam(2, v->value); |
|
123 DrawString(34, 57 + y_offset, STR_9011_BUILT_VALUE, 0); |
|
124 |
|
125 if (RoadVehHasArticPart(v)) { |
|
126 AcceptedCargo max_cargo; |
|
127 char capacity[512]; |
|
128 |
|
129 memset(max_cargo, 0, sizeof(max_cargo)); |
|
130 |
|
131 for (const Vehicle *u = v; u != NULL; u = u->next) { |
|
132 max_cargo[u->cargo_type] += u->cargo_cap; |
|
133 } |
|
134 |
|
135 GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity)); |
|
136 |
|
137 bool first = true; |
|
138 for (CargoID i = 0; i < NUM_CARGO; i++) { |
|
139 if (max_cargo[i] > 0) { |
|
140 char buffer[128]; |
|
141 |
|
142 SetDParam(0, i); |
|
143 SetDParam(1, max_cargo[i]); |
|
144 GetString(buffer, STR_BARE_CARGO, lastof(buffer)); |
|
145 |
|
146 if (!first) strecat(capacity, ", ", lastof(capacity)); |
|
147 strecat(capacity, buffer, lastof(capacity)); |
|
148 } |
|
149 } |
|
150 |
|
151 SetDParamStr(0, capacity); |
|
152 DrawStringTruncated(34, 67 + y_offset, STR_JUST_STRING, 0, w->width - 34); |
|
153 |
|
154 for (const Vehicle *u = v; u != NULL; u = u->next) { |
|
155 str = STR_8812_EMPTY; |
|
156 if (!u->cargo.Empty()) { |
|
157 SetDParam(0, u->cargo_type); |
|
158 SetDParam(1, u->cargo.Count()); |
|
159 SetDParam(2, u->cargo.Source()); |
|
160 str = STR_8813_FROM; |
|
161 } |
|
162 DrawString(34, 78 + y_offset, str, 0); |
|
163 |
|
164 y_offset += 11; |
|
165 } |
|
166 |
|
167 y_offset -= 11; |
|
168 } else { |
|
169 SetDParam(0, v->cargo_type); |
|
170 SetDParam(1, v->cargo_cap); |
|
171 DrawString(34, 67 + y_offset, STR_9012_CAPACITY, 0); |
|
172 |
|
173 str = STR_8812_EMPTY; |
|
174 if (!v->cargo.Empty()) { |
|
175 SetDParam(0, v->cargo_type); |
|
176 SetDParam(1, v->cargo.Count()); |
|
177 SetDParam(2, v->cargo.Source()); |
|
178 str = STR_8813_FROM; |
|
179 } |
|
180 DrawString(34, 78 + y_offset, str, 0); |
|
181 } |
|
182 |
|
183 /* Draw Transfer credits text */ |
|
184 SetDParam(0, v->cargo.FeederShare()); |
|
185 DrawString(34, 90 + y_offset, STR_FEEDER_CARGO_VALUE, 0); |
|
186 |
79 /* Draw service interval text */ |
187 /* Draw service interval text */ |
80 { |
188 { |
81 SetDParam(0, v->service_interval); |
189 SetDParam(0, v->service_interval); |
82 SetDParam(1, v->date_of_last_service); |
190 SetDParam(1, v->date_of_last_service); |
83 DrawString(13, 102, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
191 DrawString(13, 102 + y_offset, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0); |
84 } |
192 } |
85 |
|
86 DrawRoadVehImage(v, 3, 57, INVALID_VEHICLE); |
|
87 |
|
88 SetDParam(0, GetCustomEngineName(v->engine_type)); |
|
89 SetDParam(1, v->build_year); |
|
90 SetDParam(2, v->value); |
|
91 DrawString(34, 57, STR_9011_BUILT_VALUE, 0); |
|
92 |
|
93 SetDParam(0, v->cargo_type); |
|
94 SetDParam(1, v->cargo_cap); |
|
95 DrawString(34, 67, STR_9012_CAPACITY, 0); |
|
96 |
|
97 str = STR_8812_EMPTY; |
|
98 if (v->cargo_count != 0) { |
|
99 SetDParam(0, v->cargo_type); |
|
100 SetDParam(1, v->cargo_count); |
|
101 SetDParam(2, v->cargo_source); |
|
102 str = STR_8813_FROM; |
|
103 } |
|
104 DrawString(34, 78, str, 0); |
|
105 |
|
106 /* Draw Transfer credits text */ |
|
107 SetDParam(0, v->cargo_feeder_share); |
|
108 DrawString(34, 89, STR_FEEDER_CARGO_VALUE, 0); |
|
109 |
|
110 } break; |
193 } break; |
111 |
194 |
112 case WE_CLICK: { |
195 case WE_CLICK: { |
113 int mod; |
196 int mod; |
114 const Vehicle *v; |
197 const Vehicle *v; |
115 switch (e->we.click.widget) { |
198 switch (e->we.click.widget) { |
116 case 2: /* rename */ |
199 case 2: /* rename */ |
117 v = GetVehicle(w->window_number); |
200 v = GetVehicle(w->window_number); |
118 SetDParam(0, v->unitnumber); |
201 SetDParam(0, v->index); |
119 ShowQueryString(v->string_id, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w, CS_ALPHANUMERAL); |
202 ShowQueryString(STR_VEHICLE_NAME, STR_902C_NAME_ROAD_VEHICLE, 31, 150, w, CS_ALPHANUMERAL); |
120 break; |
203 break; |
121 |
204 |
122 case 5: /* increase int */ |
205 case 5: /* increase int */ |
123 mod = _ctrl_pressed? 5 : 10; |
206 mod = _ctrl_pressed? 5 : 10; |
124 goto do_change_service_int; |
207 goto do_change_service_int; |
149 static const Widget _roadveh_details_widgets[] = { |
232 static const Widget _roadveh_details_widgets[] = { |
150 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
233 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
151 { WWT_CAPTION, RESIZE_NONE, 14, 11, 339, 0, 13, STR_900C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
234 { WWT_CAPTION, RESIZE_NONE, 14, 11, 339, 0, 13, STR_900C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
152 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 340, 379, 0, 13, STR_01AA_NAME, STR_902E_NAME_ROAD_VEHICLE}, |
235 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 340, 379, 0, 13, STR_01AA_NAME, STR_902E_NAME_ROAD_VEHICLE}, |
153 { WWT_PANEL, RESIZE_NONE, 14, 0, 379, 14, 55, 0x0, STR_NULL}, |
236 { WWT_PANEL, RESIZE_NONE, 14, 0, 379, 14, 55, 0x0, STR_NULL}, |
154 { WWT_PANEL, RESIZE_NONE, 14, 0, 379, 56, 100, 0x0, STR_NULL}, |
237 { WWT_PANEL, RESIZE_BOTTOM, 14, 0, 379, 56, 100, 0x0, STR_NULL}, |
155 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
238 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 101, 106, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
156 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
239 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 107, 112, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
157 { WWT_PANEL, RESIZE_NONE, 14, 11, 379, 101, 112, 0x0, STR_NULL}, |
240 { WWT_PANEL, RESIZE_TB, 14, 11, 379, 101, 112, 0x0, STR_NULL}, |
158 { WIDGETS_END}, |
241 { WIDGETS_END}, |
159 }; |
242 }; |
160 |
243 |
161 static const WindowDesc _roadveh_details_desc = { |
244 static const WindowDesc _roadveh_details_desc = { |
162 WDP_AUTO, WDP_AUTO, 380, 113, |
245 WDP_AUTO, WDP_AUTO, 380, 113, |