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(GetRoadVehImage(v, 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); |
74 SetDParam(0, v->reliability * 100 >> 16); |
114 SetDParam(0, v->reliability * 100 >> 16); |
75 SetDParam(1, v->breakdowns_since_last_service); |
115 SetDParam(1, v->breakdowns_since_last_service); |
76 DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0); |
116 DrawString(2, 45, STR_9010_RELIABILITY_BREAKDOWNS, 0); |
77 } |
117 } |
78 |
118 |
|
119 DrawRoadVehImage(v, 3, 57, 0, INVALID_VEHICLE); |
|
120 |
|
121 SetDParam(0, GetCustomEngineName(v->engine_type)); |
|
122 SetDParam(1, v->build_year); |
|
123 SetDParam(2, v->value); |
|
124 DrawString(34, 57 + y_offset, STR_9011_BUILT_VALUE, 0); |
|
125 |
|
126 if (RoadVehHasArticPart(v)) { |
|
127 AcceptedCargo max_cargo; |
|
128 char capacity[512]; |
|
129 |
|
130 memset(max_cargo, 0, sizeof(max_cargo)); |
|
131 |
|
132 for (const Vehicle *u = v; u != NULL; u = u->next) { |
|
133 max_cargo[u->cargo_type] += u->cargo_cap; |
|
134 } |
|
135 |
|
136 GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity)); |
|
137 |
|
138 bool first = true; |
|
139 for (CargoID i = 0; i < NUM_CARGO; i++) { |
|
140 if (max_cargo[i] > 0) { |
|
141 char buffer[128]; |
|
142 |
|
143 SetDParam(0, i); |
|
144 SetDParam(1, max_cargo[i]); |
|
145 GetString(buffer, STR_BARE_CARGO, lastof(buffer)); |
|
146 |
|
147 if (!first) strecat(capacity, ", ", lastof(capacity)); |
|
148 strecat(capacity, buffer, lastof(capacity)); |
|
149 } |
|
150 } |
|
151 |
|
152 SetDParamStr(0, capacity); |
|
153 DrawStringTruncated(34, 67 + y_offset, STR_JUST_STRING, 0, w->width - 34); |
|
154 |
|
155 for (const Vehicle *u = v; u != NULL; u = u->next) { |
|
156 str = STR_8812_EMPTY; |
|
157 if (u->cargo_count != 0) { |
|
158 SetDParam(0, u->cargo_type); |
|
159 SetDParam(1, u->cargo_count); |
|
160 SetDParam(2, u->cargo_source); |
|
161 str = STR_8813_FROM; |
|
162 } |
|
163 DrawString(34, 78 + y_offset, str, 0); |
|
164 |
|
165 y_offset += 11; |
|
166 } |
|
167 |
|
168 y_offset -= 11; |
|
169 } else { |
|
170 SetDParam(0, v->cargo_type); |
|
171 SetDParam(1, v->cargo_cap); |
|
172 DrawString(34, 67 + y_offset, STR_9012_CAPACITY, 0); |
|
173 |
|
174 str = STR_8812_EMPTY; |
|
175 if (v->cargo_count != 0) { |
|
176 SetDParam(0, v->cargo_type); |
|
177 SetDParam(1, v->cargo_count); |
|
178 SetDParam(2, v->cargo_source); |
|
179 str = STR_8813_FROM; |
|
180 } |
|
181 DrawString(34, 78 + y_offset, str, 0); |
|
182 } |
|
183 |
|
184 /* Draw Transfer credits text */ |
|
185 SetDParam(0, v->cargo_feeder_share); |
|
186 DrawString(34, 90 + y_offset, STR_FEEDER_CARGO_VALUE, 0); |
|
187 |
79 /* Draw service interval text */ |
188 /* Draw service interval text */ |
80 { |
189 { |
81 SetDParam(0, v->service_interval); |
190 SetDParam(0, v->service_interval); |
82 SetDParam(1, v->date_of_last_service); |
191 SetDParam(1, v->date_of_last_service); |
83 DrawString(13, 102, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
192 DrawString(13, 102 + y_offset, _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0); |
84 } |
193 } |
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; |
194 } break; |
111 |
195 |
112 case WE_CLICK: { |
196 case WE_CLICK: { |
113 int mod; |
197 int mod; |
114 const Vehicle *v; |
198 const Vehicle *v; |
149 static const Widget _roadveh_details_widgets[] = { |
233 static const Widget _roadveh_details_widgets[] = { |
150 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
234 { 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}, |
235 { 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}, |
236 { 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}, |
237 { 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}, |
238 { 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}, |
239 { 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}, |
240 { 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}, |
241 { WWT_PANEL, RESIZE_TB, 14, 11, 379, 101, 112, 0x0, STR_NULL}, |
158 { WIDGETS_END}, |
242 { WIDGETS_END}, |
159 }; |
243 }; |
160 |
244 |
161 static const WindowDesc _roadveh_details_desc = { |
245 static const WindowDesc _roadveh_details_desc = { |
162 WDP_AUTO, WDP_AUTO, 380, 113, |
246 WDP_AUTO, WDP_AUTO, 380, 113, |