|
1 /* $Id$ */ |
|
2 |
|
3 #include "stdafx.h" |
|
4 #include "openttd.h" |
|
5 #include "debug.h" |
|
6 #include "functions.h" |
|
7 #include "ship.h" |
|
8 #include "table/strings.h" |
|
9 #include "table/sprites.h" |
|
10 #include "map.h" |
|
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" |
|
20 #include "depot.h" |
|
21 #include "vehicle_gui.h" |
|
22 #include "newgrf_engine.h" |
|
23 #include "date.h" |
|
24 |
|
25 /** |
|
26 * Draw the purchase info details of a ship at a given location. |
|
27 * @param x,y location where to draw the info |
|
28 * @param engine_number the engine of which to draw the info of |
|
29 */ |
|
30 void DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number) |
|
31 { |
|
32 YearMonthDay ymd; |
|
33 const ShipVehicleInfo *svi = ShipVehInfo(engine_number); |
|
34 const Engine *e; |
|
35 |
|
36 /* Purchase cost - Max speed */ |
|
37 SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5); |
|
38 SetDParam(1, svi->max_speed / 2); |
|
39 DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0); |
|
40 y += 10; |
|
41 |
|
42 /* Cargo type + capacity */ |
|
43 SetDParam(0, svi->cargo_type); |
|
44 SetDParam(1, svi->capacity); |
|
45 SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY); |
|
46 DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); |
|
47 y += 10; |
|
48 |
|
49 /* Running cost */ |
|
50 SetDParam(0, svi->running_cost * _price.ship_running >> 8); |
|
51 DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); |
|
52 y += 10; |
|
53 |
|
54 /* Design date - Life length */ |
|
55 e = GetEngine(engine_number); |
|
56 ConvertDateToYMD(e->intro_date, &ymd); |
|
57 SetDParam(0, ymd.year); |
|
58 SetDParam(1, e->lifelength); |
|
59 DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); |
|
60 y += 10; |
|
61 |
|
62 /* Reliability */ |
|
63 SetDParam(0, e->reliability * 100 >> 16); |
|
64 DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0); |
|
65 y += 10; |
|
66 |
|
67 /* Additional text from NewGRF */ |
|
68 y += ShowAdditionalText(x, y, w, engine_number); |
|
69 if (svi->refittable) y += ShowRefitOptionsList(x, y, w, engine_number); |
|
70 } |
|
71 |
|
72 void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection) |
|
73 { |
|
74 DrawSprite(GetShipImage(v, DIR_W) | GetVehiclePalette(v), x + 32, y + 10); |
|
75 |
|
76 if (v->index == selection) { |
|
77 DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY); |
|
78 } |
|
79 } |
|
80 |
|
81 static void ShipDetailsWndProc(Window *w, WindowEvent *e) |
|
82 { |
|
83 switch (e->event) { |
|
84 case WE_PAINT: { |
|
85 const Vehicle *v = GetVehicle(w->window_number); |
|
86 StringID str; |
|
87 |
|
88 SetWindowWidgetDisabledState(w, 2, v->owner != _local_player); |
|
89 // disable service-scroller when interval is set to disabled |
|
90 SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships); |
|
91 SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships); |
|
92 |
|
93 SetDParam(0, v->string_id); |
|
94 SetDParam(1, v->unitnumber); |
|
95 DrawWindowWidgets(w); |
|
96 |
|
97 /* Draw running cost */ |
|
98 { |
|
99 int year = v->age / 366; |
|
100 |
|
101 SetDParam(1, year); |
|
102 |
|
103 SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED); |
|
104 SetDParam(2, v->max_age / 366); |
|
105 SetDParam(3, ShipVehInfo(v->engine_type)->running_cost * _price.ship_running >> 8); |
|
106 DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0); |
|
107 } |
|
108 |
|
109 /* Draw max speed */ |
|
110 { |
|
111 SetDParam(0, v->max_speed / 2); |
|
112 DrawString(2, 25, STR_9813_MAX_SPEED, 0); |
|
113 } |
|
114 |
|
115 /* Draw profit */ |
|
116 { |
|
117 SetDParam(0, v->profit_this_year); |
|
118 SetDParam(1, v->profit_last_year); |
|
119 DrawString(2, 35, STR_9814_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
|
120 } |
|
121 |
|
122 /* Draw breakdown & reliability */ |
|
123 { |
|
124 SetDParam(0, v->reliability * 100 >> 16); |
|
125 SetDParam(1, v->breakdowns_since_last_service); |
|
126 DrawString(2, 45, STR_9815_RELIABILITY_BREAKDOWNS, 0); |
|
127 } |
|
128 |
|
129 /* Draw service interval text */ |
|
130 { |
|
131 SetDParam(0, v->service_interval); |
|
132 SetDParam(1, v->date_of_last_service); |
|
133 DrawString(13, 90, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); |
|
134 } |
|
135 |
|
136 DrawShipImage(v, 3, 57, INVALID_VEHICLE); |
|
137 |
|
138 SetDParam(1, v->build_year); |
|
139 SetDParam(0, GetCustomEngineName(v->engine_type)); |
|
140 SetDParam(2, v->value); |
|
141 DrawString(74, 57, STR_9816_BUILT_VALUE, 0); |
|
142 |
|
143 SetDParam(0, v->cargo_type); |
|
144 SetDParam(1, v->cargo_cap); |
|
145 DrawString(74, 67, STR_9817_CAPACITY, 0); |
|
146 |
|
147 str = STR_8812_EMPTY; |
|
148 if (v->cargo_count != 0) { |
|
149 SetDParam(0, v->cargo_type); |
|
150 SetDParam(1, v->cargo_count); |
|
151 SetDParam(2, v->cargo_source); |
|
152 str = STR_8813_FROM; |
|
153 } |
|
154 DrawString(74, 78, str, 0); |
|
155 } break; |
|
156 |
|
157 case WE_CLICK: { |
|
158 int mod; |
|
159 const Vehicle *v; |
|
160 switch (e->we.click.widget) { |
|
161 case 2: /* rename */ |
|
162 v = GetVehicle(w->window_number); |
|
163 SetDParam(0, v->unitnumber); |
|
164 ShowQueryString(v->string_id, STR_9831_NAME_SHIP, 31, 150, w, CS_ALPHANUMERAL); |
|
165 break; |
|
166 case 5: /* increase int */ |
|
167 mod = _ctrl_pressed? 5 : 10; |
|
168 goto do_change_service_int; |
|
169 case 6: /* decrease int */ |
|
170 mod = _ctrl_pressed?- 5 : -10; |
|
171 do_change_service_int: |
|
172 v = GetVehicle(w->window_number); |
|
173 |
|
174 mod = GetServiceIntervalClamped(mod + v->service_interval); |
|
175 if (mod == v->service_interval) return; |
|
176 |
|
177 DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
|
178 break; |
|
179 } |
|
180 } break; |
|
181 |
|
182 case WE_ON_EDIT_TEXT: |
|
183 if (e->we.edittext.str[0] != '\0') { |
|
184 _cmd_text = e->we.edittext.str; |
|
185 DoCommandP(0, w->window_number, 0, NULL, |
|
186 CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP)); |
|
187 } |
|
188 break; |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 static const Widget _ship_details_widgets[] = { |
|
194 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
195 { WWT_CAPTION, RESIZE_NONE, 14, 11, 364, 0, 13, STR_9811_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
196 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 365, 404, 0, 13, STR_01AA_NAME, STR_982F_NAME_SHIP}, |
|
197 { WWT_PANEL, RESIZE_NONE, 14, 0, 404, 14, 55, 0x0, STR_NULL}, |
|
198 { WWT_PANEL, RESIZE_NONE, 14, 0, 404, 56, 88, 0x0, STR_NULL}, |
|
199 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 89, 94, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
|
200 { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 95, 100, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
|
201 { WWT_PANEL, RESIZE_NONE, 14, 11, 404, 89, 100, 0x0, STR_NULL}, |
|
202 { WIDGETS_END}, |
|
203 }; |
|
204 |
|
205 static const WindowDesc _ship_details_desc = { |
|
206 WDP_AUTO, WDP_AUTO, 405, 101, |
|
207 WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
|
208 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
209 _ship_details_widgets, |
|
210 ShipDetailsWndProc |
|
211 }; |
|
212 |
|
213 static void ShowShipDetailsWindow(const Vehicle *v) |
|
214 { |
|
215 Window *w; |
|
216 VehicleID veh = v->index; |
|
217 |
|
218 DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
|
219 DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
220 w = AllocateWindowDescFront(&_ship_details_desc, veh); |
|
221 w->caption_color = v->owner; |
|
222 } |
|
223 |
|
224 void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) |
|
225 { |
|
226 const Vehicle *v; |
|
227 if (!success) return; |
|
228 |
|
229 v = GetVehicle(_new_vehicle_id); |
|
230 if (v->tile == _backup_orders_tile) { |
|
231 _backup_orders_tile = 0; |
|
232 RestoreVehicleOrders(v, _backup_orders_data); |
|
233 } |
|
234 ShowShipViewWindow(v); |
|
235 } |
|
236 |
|
237 void CcCloneShip(bool success, TileIndex tile, uint32 p1, uint32 p2) |
|
238 { |
|
239 if (success) ShowShipViewWindow(GetVehicle(_new_vehicle_id)); |
|
240 } |
|
241 |
|
242 static void NewShipWndProc(Window *w, WindowEvent *e) |
|
243 { |
|
244 switch (e->event) { |
|
245 case WE_PAINT: { |
|
246 EngineID selected_id; |
|
247 EngineID eid; |
|
248 int count; |
|
249 int pos; |
|
250 int sel; |
|
251 int y; |
|
252 |
|
253 SetWindowWidgetDisabledState(w, 5, w->window_number == 0); |
|
254 |
|
255 count = 0; |
|
256 for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { |
|
257 if (HASBIT(GetEngine(eid)->player_avail, _local_player)) count++; |
|
258 } |
|
259 SetVScrollCount(w, count); |
|
260 |
|
261 DrawWindowWidgets(w); |
|
262 |
|
263 y = 15; |
|
264 sel = WP(w,buildvehicle_d).sel_index; |
|
265 pos = w->vscroll.pos; |
|
266 selected_id = INVALID_ENGINE; |
|
267 for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) { |
|
268 if (!HASBIT(GetEngine(eid)->player_avail, _local_player)) continue; |
|
269 if (sel == 0) selected_id = eid; |
|
270 if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { |
|
271 DrawString(77, y + 7, GetCustomEngineName(eid), sel == 0 ? 0xC : 0x10); |
|
272 DrawShipEngine(37, y + 10, eid, GetEnginePalette(eid, _local_player)); |
|
273 y += 24; |
|
274 } |
|
275 sel--; |
|
276 } |
|
277 |
|
278 WP(w,buildvehicle_d).sel_engine = selected_id; |
|
279 |
|
280 if (selected_id != INVALID_ENGINE) { |
|
281 const Widget *wi = &w->widget[4]; |
|
282 DrawShipPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id); |
|
283 } |
|
284 break; |
|
285 } |
|
286 |
|
287 case WE_CLICK: |
|
288 switch (e->we.click.widget) { |
|
289 case 2: { /* listbox */ |
|
290 uint i = (e->we.click.pt.y - 14) / 24; |
|
291 if (i < w->vscroll.cap) { |
|
292 WP(w,buildvehicle_d).sel_index = i + w->vscroll.pos; |
|
293 SetWindowDirty(w); |
|
294 } |
|
295 } break; |
|
296 case 5: { /* build */ |
|
297 EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; |
|
298 if (sel_eng != INVALID_ENGINE) |
|
299 DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); |
|
300 } break; |
|
301 |
|
302 case 6: { /* rename */ |
|
303 EngineID sel_eng = WP(w,buildvehicle_d).sel_engine; |
|
304 if (sel_eng != INVALID_ENGINE) { |
|
305 WP(w, buildvehicle_d).rename_engine = sel_eng; |
|
306 ShowQueryString(GetCustomEngineName(sel_eng), STR_9838_RENAME_SHIP_TYPE, 31, 160, w, CS_ALPHANUMERAL); |
|
307 } |
|
308 } break; |
|
309 } |
|
310 break; |
|
311 |
|
312 case WE_ON_EDIT_TEXT: |
|
313 if (e->we.edittext.str[0] != '\0') { |
|
314 _cmd_text = e->we.edittext.str; |
|
315 DoCommandP(0, WP(w, buildvehicle_d).rename_engine, 0, NULL, |
|
316 CMD_RENAME_ENGINE | CMD_MSG(STR_9839_CAN_T_RENAME_SHIP_TYPE)); |
|
317 } |
|
318 break; |
|
319 |
|
320 case WE_RESIZE: |
|
321 w->vscroll.cap += e->we.sizing.diff.y / 24; |
|
322 w->widget[2].data = (w->vscroll.cap << 8) + 1; |
|
323 break; |
|
324 |
|
325 } |
|
326 } |
|
327 |
|
328 static const Widget _new_ship_widgets[] = { |
|
329 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
330 { WWT_CAPTION, RESIZE_NONE, 14, 11, 254, 0, 13, STR_9808_NEW_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
331 { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 242, 14, 109, 0x401, STR_9825_SHIP_SELECTION_LIST_CLICK}, |
|
332 { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 243, 254, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
333 { WWT_PANEL, RESIZE_TB, 14, 0, 254, 110, 201, 0x0, STR_NULL}, |
|
334 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 121, 202, 213, STR_9809_BUILD_SHIP, STR_9826_BUILD_THE_HIGHLIGHTED_SHIP}, |
|
335 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 122, 242, 202, 213, STR_9836_RENAME, STR_9837_RENAME_SHIP_TYPE}, |
|
336 { WWT_RESIZEBOX, RESIZE_TB, 14, 243, 254, 202, 213, 0x0, STR_RESIZE_BUTTON}, |
|
337 { WIDGETS_END}, |
|
338 }; |
|
339 |
|
340 static const WindowDesc _new_ship_desc = { |
|
341 WDP_AUTO, WDP_AUTO, 255, 214, |
|
342 WC_BUILD_VEHICLE,0, |
|
343 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
|
344 _new_ship_widgets, |
|
345 NewShipWndProc |
|
346 }; |
|
347 |
|
348 |
|
349 void ShowBuildShipWindow(TileIndex tile) |
|
350 { |
|
351 Window *w; |
|
352 |
|
353 DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
354 |
|
355 w = AllocateWindowDescFront(&_new_ship_desc, tile); |
|
356 w->vscroll.cap = 4; |
|
357 w->widget[2].data = (w->vscroll.cap << 8) + 1; |
|
358 |
|
359 w->resize.step_height = 24; |
|
360 |
|
361 if (tile != 0) { |
|
362 w->caption_color = GetTileOwner(tile); |
|
363 } else { |
|
364 w->caption_color = _local_player; |
|
365 } |
|
366 |
|
367 } |
|
368 |
|
369 |
|
370 static void ShipViewWndProc(Window *w, WindowEvent *e) |
|
371 { |
|
372 switch (e->event) { |
|
373 case WE_PAINT: { |
|
374 Vehicle *v = GetVehicle(w->window_number); |
|
375 StringID str; |
|
376 bool refitable_and_stopped_in_depot = ShipVehInfo(v->engine_type)->refittable && IsShipInDepotStopped(v); |
|
377 bool is_localplayer = v->owner == _local_player; |
|
378 |
|
379 SetWindowWidgetDisabledState(w, 7, !is_localplayer); |
|
380 SetWindowWidgetDisabledState(w, 8, |
|
381 !is_localplayer || // Disable if owner is not local player |
|
382 !refitable_and_stopped_in_depot); // Disable if the ship is not refitable or stopped in a depot |
|
383 SetWindowWidgetDisabledState(w, 11, !is_localplayer); |
|
384 |
|
385 /* draw widgets & caption */ |
|
386 SetDParam(0, v->string_id); |
|
387 SetDParam(1, v->unitnumber); |
|
388 DrawWindowWidgets(w); |
|
389 |
|
390 if (v->breakdown_ctr == 1) { |
|
391 str = STR_885C_BROKEN_DOWN; |
|
392 } else if (v->vehstatus & VS_STOPPED) { |
|
393 str = STR_8861_STOPPED; |
|
394 } else { |
|
395 switch (v->current_order.type) { |
|
396 case OT_GOTO_STATION: { |
|
397 SetDParam(0, v->current_order.dest); |
|
398 SetDParam(1, v->cur_speed / 2); |
|
399 str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
|
400 } break; |
|
401 |
|
402 case OT_GOTO_DEPOT: { |
|
403 Depot *depot = GetDepot(v->current_order.dest); |
|
404 SetDParam(0, depot->town_index); |
|
405 SetDParam(1, v->cur_speed / 2); |
|
406 if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { |
|
407 str = STR_HEADING_FOR_SHIP_DEPOT + _patches.vehicle_speed; |
|
408 } else { |
|
409 str = STR_HEADING_FOR_SHIP_DEPOT_SERVICE + _patches.vehicle_speed; |
|
410 } |
|
411 } break; |
|
412 |
|
413 case OT_LOADING: |
|
414 case OT_LEAVESTATION: |
|
415 str = STR_882F_LOADING_UNLOADING; |
|
416 break; |
|
417 |
|
418 default: |
|
419 if (v->num_orders == 0) { |
|
420 str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
421 SetDParam(0, v->cur_speed / 2); |
|
422 } else { |
|
423 str = STR_EMPTY; |
|
424 } |
|
425 break; |
|
426 } |
|
427 } |
|
428 |
|
429 /* draw the flag plus orders */ |
|
430 DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1); |
|
431 DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0); |
|
432 DrawWindowViewport(w); |
|
433 } break; |
|
434 |
|
435 case WE_CLICK: { |
|
436 const Vehicle *v = GetVehicle(w->window_number); |
|
437 |
|
438 switch (e->we.click.widget) { |
|
439 case 5: /* start stop */ |
|
440 DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP)); |
|
441 break; |
|
442 case 6: /* center main view */ |
|
443 ScrollMainWindowTo(v->x_pos, v->y_pos); |
|
444 break; |
|
445 case 7: /* goto hangar */ |
|
446 DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT)); |
|
447 break; |
|
448 case 8: /* refit */ |
|
449 ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID); |
|
450 break; |
|
451 case 9: /* show orders */ |
|
452 ShowOrdersWindow(v); |
|
453 break; |
|
454 case 10: /* show details */ |
|
455 ShowShipDetailsWindow(v); |
|
456 break; |
|
457 case 11: { |
|
458 /* clone vehicle */ |
|
459 DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)); |
|
460 } break; |
|
461 } |
|
462 } break; |
|
463 |
|
464 case WE_RESIZE: |
|
465 w->viewport->width += e->we.sizing.diff.x; |
|
466 w->viewport->height += e->we.sizing.diff.y; |
|
467 w->viewport->virtual_width += e->we.sizing.diff.x; |
|
468 w->viewport->virtual_height += e->we.sizing.diff.y; |
|
469 break; |
|
470 |
|
471 case WE_DESTROY: |
|
472 DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
|
473 DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); |
|
474 DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
|
475 break; |
|
476 |
|
477 case WE_MOUSELOOP: { |
|
478 const Vehicle *v = GetVehicle(w->window_number); |
|
479 bool ship_stopped = IsShipInDepotStopped(v); |
|
480 |
|
481 /* Widget 7 (send to depot) must be hidden if the ship is already stopped in depot. |
|
482 * Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped. |
|
483 * This sytem allows to have two buttons, on top of each otherother*/ |
|
484 if (ship_stopped != IsWindowWidgetHidden(w, 7) || ship_stopped == IsWindowWidgetHidden(w, 11)) { |
|
485 SetWindowWidgetHiddenState(w, 7, ship_stopped); // send to depot |
|
486 SetWindowWidgetHiddenState(w, 11, !ship_stopped); // clone |
|
487 SetWindowDirty(w); |
|
488 } |
|
489 } |
|
490 } |
|
491 } |
|
492 |
|
493 static const Widget _ship_view_widgets[] = { |
|
494 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
495 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_980F, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
496 { WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON}, |
|
497 { WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 103, 0x0, STR_NULL}, |
|
498 { WWT_INSET, RESIZE_RB, 14, 2, 229, 16, 101, 0x0, STR_NULL}, |
|
499 { WWT_PUSHBTN, RESIZE_RTB, 14, 0, 237, 104, 115, 0x0, STR_9827_CURRENT_SHIP_ACTION_CLICK}, |
|
500 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, SPR_CENTRE_VIEW_VEHICLE, STR_9829_CENTER_MAIN_VIEW_ON_SHIP}, |
|
501 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_SEND_SHIP_TODEPOT, STR_982A_SEND_SHIP_TO_DEPOT}, |
|
502 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, SPR_REFIT_VEHICLE, STR_983A_REFIT_CARGO_SHIP_TO_CARRY}, |
|
503 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, SPR_SHOW_ORDERS, STR_9828_SHOW_SHIP_S_ORDERS}, |
|
504 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, SPR_SHOW_VEHICLE_DETAILS,STR_982B_SHOW_SHIP_DETAILS}, |
|
505 { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_SHIP, STR_CLONE_SHIP_INFO}, |
|
506 { WWT_PANEL, RESIZE_LRB, 14, 232, 249, 104, 103, 0x0, STR_NULL }, |
|
507 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 104, 115, 0x0, STR_NULL }, |
|
508 { WIDGETS_END } |
|
509 }; |
|
510 |
|
511 static const WindowDesc _ship_view_desc = { |
|
512 WDP_AUTO, WDP_AUTO, 250, 116, |
|
513 WC_VEHICLE_VIEW,0, |
|
514 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
|
515 _ship_view_widgets, |
|
516 ShipViewWndProc |
|
517 }; |
|
518 |
|
519 void ShowShipViewWindow(const Vehicle *v) |
|
520 { |
|
521 Window *w = AllocateWindowDescFront(&_ship_view_desc, v->index); |
|
522 |
|
523 if (w != NULL) { |
|
524 w->caption_color = v->owner; |
|
525 AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0); |
|
526 } |
|
527 } |