21 #include "waypoint.h" |
21 #include "waypoint.h" |
22 #include "train.h" |
22 #include "train.h" |
23 #include "water_map.h" |
23 #include "water_map.h" |
24 #include "vehicle_gui.h" |
24 #include "vehicle_gui.h" |
25 |
25 |
|
26 enum OrderWindowWidgets { |
|
27 ORDER_WIDGET_CLOSEBOX = 0, |
|
28 ORDER_WIDGET_CAPTION, |
|
29 ORDER_WIDGET_ORDER_LIST, |
|
30 ORDER_WIDGET_SCROLLBAR, |
|
31 ORDER_WIDGET_SKIP, |
|
32 ORDER_WIDGET_DELETE, |
|
33 ORDER_WIDGET_NON_STOP, |
|
34 ORDER_WIDGET_GOTO, |
|
35 ORDER_WIDGET_FULL_LOAD, |
|
36 ORDER_WIDGET_UNLOAD, |
|
37 ORDER_WIDGET_TRANSFER, |
|
38 ORDER_WIDGET_SHARED_ORDER_LIST, |
|
39 ORDER_WIDGET_REFIT, |
|
40 ORDER_WIDGET_RESIZE_BAR, |
|
41 ORDER_WIDGET_RESIZE, |
|
42 }; |
|
43 |
26 static int OrderGetSel(const Window *w) |
44 static int OrderGetSel(const Window *w) |
27 { |
45 { |
28 const Vehicle *v = GetVehicle(w->window_number); |
46 const Vehicle *v = GetVehicle(w->window_number); |
29 int num = WP(w,order_d).sel; |
47 int num = WP(w,order_d).sel; |
30 |
48 |
70 |
88 |
71 order = GetVehicleOrder(v, sel); |
89 order = GetVehicleOrder(v, sel); |
72 |
90 |
73 if (v->owner == _local_player) { |
91 if (v->owner == _local_player) { |
74 /* skip */ |
92 /* skip */ |
75 SetWindowWidgetDisabledState(w, 4, v->num_orders == 0); |
93 SetWindowWidgetDisabledState(w, ORDER_WIDGET_SKIP, v->num_orders == 0); |
76 |
94 |
77 /* delete */ |
95 /* delete */ |
78 SetWindowWidgetDisabledState(w, 5, |
96 SetWindowWidgetDisabledState(w, ORDER_WIDGET_DELETE, |
79 (uint)v->num_orders + (shared_orders ? 1 : 0) <= (uint)WP(w, order_d).sel); |
97 (uint)v->num_orders + (shared_orders ? 1 : 0) <= (uint)WP(w, order_d).sel); |
80 |
98 |
81 /* non-stop only for trains */ |
99 /* non-stop only for trains */ |
82 SetWindowWidgetDisabledState(w, 6, v->type != VEH_Train || order == NULL); |
100 SetWindowWidgetDisabledState(w, ORDER_WIDGET_NON_STOP, v->type != VEH_Train || order == NULL); |
83 SetWindowWidgetDisabledState(w, 8, order == NULL); // full load |
101 SetWindowWidgetDisabledState(w, ORDER_WIDGET_FULL_LOAD, order == NULL); // full load |
84 SetWindowWidgetDisabledState(w, 9, order == NULL); // unload |
102 SetWindowWidgetDisabledState(w, ORDER_WIDGET_UNLOAD, order == NULL); // unload |
85 SetWindowWidgetDisabledState(w, 10, order == NULL); // transfer |
103 SetWindowWidgetDisabledState(w, ORDER_WIDGET_TRANSFER, order == NULL); // transfer |
86 /* Disable list of vehicles with the same shared orders if there is no list */ |
104 /* Disable list of vehicles with the same shared orders if there is no list */ |
87 SetWindowWidgetDisabledState(w, 11, !shared_orders || v->orders == NULL); |
105 SetWindowWidgetDisabledState(w, ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL); |
88 SetWindowWidgetDisabledState(w, 12, order == NULL); // Refit |
106 SetWindowWidgetDisabledState(w, ORDER_WIDGET_REFIT, order == NULL); // Refit |
89 HideWindowWidget(w, 12); // Refit |
107 HideWindowWidget(w, ORDER_WIDGET_REFIT); // Refit |
90 } else { |
108 } else { |
91 DisableWindowWidget(w, 10); |
109 DisableWindowWidget(w, ORDER_WIDGET_TRANSFER); |
92 } |
110 } |
93 |
111 |
94 ShowWindowWidget(w, 9); // Unload |
112 ShowWindowWidget(w, ORDER_WIDGET_UNLOAD); // Unload |
95 |
113 |
96 if (order != NULL) { |
114 if (order != NULL) { |
97 switch (order->type) { |
115 switch (order->type) { |
98 case OT_GOTO_STATION: break; |
116 case OT_GOTO_STATION: break; |
99 |
117 |
100 case OT_GOTO_DEPOT: |
118 case OT_GOTO_DEPOT: |
101 DisableWindowWidget(w, 10); |
119 DisableWindowWidget(w, ORDER_WIDGET_TRANSFER); |
102 |
120 |
103 /* Remove unload and replace it with refit */ |
121 /* Remove unload and replace it with refit */ |
104 HideWindowWidget(w, 9); |
122 HideWindowWidget(w, ORDER_WIDGET_UNLOAD); |
105 ShowWindowWidget(w, 12); |
123 ShowWindowWidget(w, ORDER_WIDGET_REFIT); |
106 SetDParam(2,STR_SERVICE); |
124 SetDParam(2,STR_SERVICE); |
107 break; |
125 break; |
108 |
126 |
109 case OT_GOTO_WAYPOINT: |
127 case OT_GOTO_WAYPOINT: |
110 DisableWindowWidget(w, 8); |
128 DisableWindowWidget(w, ORDER_WIDGET_FULL_LOAD); |
111 DisableWindowWidget(w, 9); |
129 DisableWindowWidget(w, ORDER_WIDGET_UNLOAD); |
112 DisableWindowWidget(w, 10); |
130 DisableWindowWidget(w, ORDER_WIDGET_TRANSFER); |
113 break; |
131 break; |
114 |
132 |
115 default: // every other orders |
133 default: // every other orders |
116 DisableWindowWidget(w, 6); |
134 DisableWindowWidget(w, ORDER_WIDGET_NON_STOP); |
117 DisableWindowWidget(w, 8); |
135 DisableWindowWidget(w, ORDER_WIDGET_FULL_LOAD); |
118 DisableWindowWidget(w, 9); |
136 DisableWindowWidget(w, ORDER_WIDGET_UNLOAD); |
119 } |
137 } |
120 } |
138 } |
121 |
139 |
122 SetDParam(0, v->string_id); |
140 SetDParam(0, v->string_id); |
123 SetDParam(1, v->unitnumber); |
141 SetDParam(1, v->unitnumber); |
336 } |
354 } |
337 } |
355 } |
338 |
356 |
339 static void OrderClick_Goto(Window *w, const Vehicle *v) |
357 static void OrderClick_Goto(Window *w, const Vehicle *v) |
340 { |
358 { |
341 InvalidateWidget(w, 7); |
359 InvalidateWidget(w, ORDER_WIDGET_GOTO); |
342 ToggleWidgetLoweredState(w, 7); |
360 ToggleWidgetLoweredState(w, ORDER_WIDGET_GOTO); |
343 if (IsWindowWidgetLowered(w, 7)) { |
361 if (IsWindowWidgetLowered(w, ORDER_WIDGET_GOTO)) { |
344 _place_clicked_vehicle = NULL; |
362 _place_clicked_vehicle = NULL; |
345 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, 1, w); |
363 SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, 1, w); |
346 } else { |
364 } else { |
347 ResetObjectToPlace(); |
365 ResetObjectToPlace(); |
348 } |
366 } |
413 { |
431 { |
414 switch (e->event) { |
432 switch (e->event) { |
415 case WE_CREATE: |
433 case WE_CREATE: |
416 /* Move Refit to the same location as Unload |
434 /* Move Refit to the same location as Unload |
417 * This will ensure that they always stay at the same location even if Unload is moved in a later commit */ |
435 * This will ensure that they always stay at the same location even if Unload is moved in a later commit */ |
418 w->widget[12].left = w->widget[9].left; |
436 w->widget[ORDER_WIDGET_REFIT].left = w->widget[ORDER_WIDGET_UNLOAD].left; |
419 w->widget[12].right = w->widget[9].right; |
437 w->widget[ORDER_WIDGET_REFIT].right = w->widget[ORDER_WIDGET_UNLOAD].right; |
420 w->widget[12].top = w->widget[9].top; |
438 w->widget[ORDER_WIDGET_REFIT].top = w->widget[ORDER_WIDGET_UNLOAD].top; |
421 w->widget[12].bottom = w->widget[9].bottom; |
439 w->widget[ORDER_WIDGET_REFIT].bottom = w->widget[ORDER_WIDGET_UNLOAD].bottom; |
422 break; |
440 break; |
423 |
441 |
424 case WE_PAINT: |
442 case WE_PAINT: |
425 DrawOrdersWindow(w); |
443 DrawOrdersWindow(w); |
426 break; |
444 break; |
427 |
445 |
428 case WE_CLICK: { |
446 case WE_CLICK: { |
429 Vehicle *v = GetVehicle(w->window_number); |
447 Vehicle *v = GetVehicle(w->window_number); |
430 switch (e->we.click.widget) { |
448 switch (e->we.click.widget) { |
431 case 2: { /* orders list */ |
449 case ORDER_WIDGET_ORDER_LIST: { |
432 int sel = (e->we.click.pt.y - 15) / 10; |
450 int sel = (e->we.click.pt.y - 15) / 10; |
433 |
451 |
434 if ((uint)sel >= w->vscroll.cap) return; |
452 if ((uint)sel >= w->vscroll.cap) return; |
435 |
453 |
436 sel += w->vscroll.pos; |
454 sel += w->vscroll.pos; |
453 if (sel == WP(w,order_d).sel) sel = -1; |
471 if (sel == WP(w,order_d).sel) sel = -1; |
454 WP(w,order_d).sel = sel; |
472 WP(w,order_d).sel = sel; |
455 SetWindowDirty(w); |
473 SetWindowDirty(w); |
456 } break; |
474 } break; |
457 |
475 |
458 case 4: /* skip button */ |
476 case ORDER_WIDGET_SKIP: |
459 OrderClick_Skip(w, v); |
477 OrderClick_Skip(w, v); |
460 break; |
478 break; |
461 |
479 |
462 case 5: /* delete button */ |
480 case ORDER_WIDGET_DELETE: |
463 OrderClick_Delete(w, v); |
481 OrderClick_Delete(w, v); |
464 break; |
482 break; |
465 |
483 |
466 case 6: /* non stop button */ |
484 case ORDER_WIDGET_NON_STOP: |
467 OrderClick_Nonstop(w, v); |
485 OrderClick_Nonstop(w, v); |
468 break; |
486 break; |
469 |
487 |
470 case 7: /* goto button */ |
488 case ORDER_WIDGET_GOTO: |
471 OrderClick_Goto(w, v); |
489 OrderClick_Goto(w, v); |
472 break; |
490 break; |
473 |
491 |
474 case 8: /* full load button */ |
492 case ORDER_WIDGET_FULL_LOAD: |
475 OrderClick_FullLoad(w, v); |
493 OrderClick_FullLoad(w, v); |
476 break; |
494 break; |
477 |
495 |
478 case 9: /* unload button */ |
496 case ORDER_WIDGET_UNLOAD: |
479 OrderClick_Unload(w, v); |
497 OrderClick_Unload(w, v); |
480 break; |
498 break; |
481 case 10: /* transfer button */ |
499 case ORDER_WIDGET_TRANSFER: |
482 OrderClick_Transfer(w, v); |
500 OrderClick_Transfer(w, v); |
483 break; |
501 break; |
484 case 11: /* Vehicle with same shared Orders button */ |
502 case ORDER_WIDGET_SHARED_ORDER_LIST: |
485 ShowVehicleListWindow(v); |
503 ShowVehicleListWindow(v); |
486 break; |
504 break; |
487 case 12: |
505 case ORDER_WIDGET_REFIT: |
488 OrderClick_Refit(w, v); |
506 OrderClick_Refit(w, v); |
489 break; |
507 break; |
490 } |
508 } |
491 } break; |
509 } break; |
492 |
510 |
498 |
516 |
499 for (i = 0; i < lengthof(_order_keycodes); i++) { |
517 for (i = 0; i < lengthof(_order_keycodes); i++) { |
500 if (e->we.keypress.keycode == _order_keycodes[i]) { |
518 if (e->we.keypress.keycode == _order_keycodes[i]) { |
501 e->we.keypress.cont = false; |
519 e->we.keypress.cont = false; |
502 //see if the button is disabled |
520 //see if the button is disabled |
503 if (!IsWindowWidgetDisabled(w, i + 4)) _order_button_proc[i](w, v); |
521 if (!IsWindowWidgetDisabled(w, i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v); |
504 break; |
522 break; |
505 } |
523 } |
506 } |
524 } |
507 break; |
525 break; |
508 } |
526 } |
509 |
527 |
510 case WE_RCLICK: { |
528 case WE_RCLICK: { |
511 const Vehicle *v = GetVehicle(w->window_number); |
529 const Vehicle *v = GetVehicle(w->window_number); |
512 int s = OrderGetSel(w); |
530 int s = OrderGetSel(w); |
513 |
531 |
514 if (e->we.click.widget != 8) break; |
532 if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break; |
515 if (s == v->num_orders || GetVehicleOrder(v, s)->type != OT_GOTO_DEPOT) { |
533 if (s == v->num_orders || GetVehicleOrder(v, s)->type != OT_GOTO_DEPOT) { |
516 GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER); |
534 GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER); |
517 } else { |
535 } else { |
518 GuiShowTooltips(STR_SERVICE_HINT); |
536 GuiShowTooltips(STR_SERVICE_HINT); |
519 } |
537 } |
537 * This is because of all open order windows WE_MOUSELOOP is called |
555 * This is because of all open order windows WE_MOUSELOOP is called |
538 * and if you have 3 windows open, and this check is not done |
556 * and if you have 3 windows open, and this check is not done |
539 * the order is copied to the last open window instead of the |
557 * the order is copied to the last open window instead of the |
540 * one where GOTO is enabled |
558 * one where GOTO is enabled |
541 */ |
559 */ |
542 if (v != NULL && IsWindowWidgetLowered(w, 7)) { |
560 if (v != NULL && IsWindowWidgetLowered(w, ORDER_WIDGET_GOTO)) { |
543 _place_clicked_vehicle = NULL; |
561 _place_clicked_vehicle = NULL; |
544 HandleOrderVehClick(GetVehicle(w->window_number), v, w); |
562 HandleOrderVehClick(GetVehicle(w->window_number), v, w); |
545 } |
563 } |
546 } break; |
564 } break; |
547 |
565 |
548 case WE_RESIZE: |
566 case WE_RESIZE: |
549 /* Update the scroll + matrix */ |
567 /* Update the scroll + matrix */ |
550 w->vscroll.cap = (w->widget[2].bottom - w->widget[2].top) / 10; |
568 w->vscroll.cap = (w->widget[ORDER_WIDGET_ORDER_LIST].bottom - w->widget[ORDER_WIDGET_ORDER_LIST].top) / 10; |
551 break; |
569 break; |
552 |
570 |
553 case WE_TIMEOUT: { // handle button unclick ourselves... |
571 case WE_TIMEOUT: { // handle button unclick ourselves... |
554 // unclick all buttons except for the 'goto' button (7), which is 'persistent' |
572 // unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' |
555 uint i; |
573 uint i; |
556 for (i = 0; i < w->widget_count; i++) { |
574 for (i = 0; i < w->widget_count; i++) { |
557 if (IsWindowWidgetLowered(w, i) && i != 7) { |
575 if (IsWindowWidgetLowered(w, i) && i != ORDER_WIDGET_GOTO) { |
558 RaiseWindowWidget(w, i); |
576 RaiseWindowWidget(w, i); |
559 InvalidateWidget(w, i); |
577 InvalidateWidget(w, i); |
560 } |
578 } |
561 } |
579 } |
562 } break; |
580 } break; |