Files
@ r11784:1f7706fe8337
Branch filter:
Location: cpp/openttd-patchpack/source/src/order_gui.cpp
r11784:1f7706fe8337
54.6 KiB
text/x-c
(svn r16179) -Update: WebTranslator2 update to 2009-04-27 17:41:22
brazilian_portuguese - 24 fixed by tucalipe (24)
dutch - 10 fixed by habell (10)
estonian - 8 changed by kristjans (8)
hungarian - 10 fixed by IPG (10)
italian - 1 changed by lorenzodv (1)
malay - 22 fixed by Syed (22)
norwegian_bokmal - 1 fixed by khh (1)
polish - 336 fixed, 104 changed by konrad (440)
brazilian_portuguese - 24 fixed by tucalipe (24)
dutch - 10 fixed by habell (10)
estonian - 8 changed by kristjans (8)
hungarian - 10 fixed by IPG (10)
italian - 1 changed by lorenzodv (1)
malay - 22 fixed by Syed (22)
norwegian_bokmal - 1 fixed by khh (1)
polish - 336 fixed, 104 changed by konrad (440)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 | /* $Id$ */
/** @file order_gui.cpp GUI related to orders. */
#include "stdafx.h"
#include "station_map.h"
#include "window_gui.h"
#include "command_func.h"
#include "viewport_func.h"
#include "gfx_func.h"
#include "depot_base.h"
#include "vehicle_base.h"
#include "vehicle_gui.h"
#include "timetable.h"
#include "cargotype.h"
#include "strings_func.h"
#include "window_func.h"
#include "vehicle_func.h"
#include "company_func.h"
#include "newgrf_cargo.h"
#include "widgets/dropdown_func.h"
#include "textbuf_gui.h"
#include "string_func.h"
#include "tilehighlight_func.h"
#include "network/network.h"
#include "settings_type.h"
#include "table/sprites.h"
#include "table/strings.h"
/** Widget numbers of the order window. */
enum OrderWindowWidgets {
ORDER_WIDGET_CLOSEBOX = 0,
ORDER_WIDGET_CAPTION,
ORDER_WIDGET_TIMETABLE_VIEW,
ORDER_WIDGET_STICKY,
ORDER_WIDGET_ORDER_LIST,
ORDER_WIDGET_SCROLLBAR,
ORDER_WIDGET_SKIP,
ORDER_WIDGET_DELETE,
ORDER_WIDGET_NON_STOP_DROPDOWN,
ORDER_WIDGET_NON_STOP,
ORDER_WIDGET_GOTO_DROPDOWN,
ORDER_WIDGET_GOTO,
ORDER_WIDGET_FULL_LOAD_DROPDOWN,
ORDER_WIDGET_FULL_LOAD,
ORDER_WIDGET_UNLOAD_DROPDOWN,
ORDER_WIDGET_UNLOAD,
ORDER_WIDGET_REFIT,
ORDER_WIDGET_SERVICE_DROPDOWN,
ORDER_WIDGET_SERVICE,
ORDER_WIDGET_COND_VARIABLE,
ORDER_WIDGET_COND_COMPARATOR,
ORDER_WIDGET_COND_VALUE,
ORDER_WIDGET_SHARED_ORDER_LIST,
ORDER_WIDGET_RESIZE,
};
/** Order load types that could be given to station orders. */
static const StringID _station_load_types[][5] = {
{
STR_EMPTY,
INVALID_STRING_ID,
STR_ORDER_FULL_LOAD,
STR_ORDER_FULL_LOAD_ANY,
STR_ORDER_NO_LOAD,
}, {
STR_ORDER_UNLOAD,
INVALID_STRING_ID,
STR_ORDER_UNLOAD_FULL_LOAD,
STR_ORDER_UNLOAD_FULL_LOAD_ANY,
STR_ORDER_UNLOAD_NO_LOAD,
}, {
STR_ORDER_TRANSFER,
INVALID_STRING_ID,
STR_ORDER_TRANSFER_FULL_LOAD,
STR_ORDER_TRANSFER_FULL_LOAD_ANY,
STR_ORDER_TRANSFER_NO_LOAD,
}, {
/* Unload and transfer do not work together. */
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
INVALID_STRING_ID,
}, {
STR_ORDER_NO_UNLOAD,
INVALID_STRING_ID,
STR_ORDER_NO_UNLOAD_FULL_LOAD,
STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
INVALID_STRING_ID,
}
};
static const StringID _order_non_stop_drowdown[] = {
STR_ORDER_GO_TO,
STR_ORDER_GO_NON_STOP_TO,
STR_ORDER_GO_VIA,
STR_ORDER_GO_NON_STOP_VIA,
INVALID_STRING_ID
};
static const StringID _order_full_load_drowdown[] = {
STR_ORDER_DROP_LOAD_IF_POSSIBLE,
STR_EMPTY,
STR_ORDER_DROP_FULL_LOAD_ALL,
STR_ORDER_DROP_FULL_LOAD_ANY,
STR_ORDER_DROP_NO_LOADING,
INVALID_STRING_ID
};
static const StringID _order_unload_drowdown[] = {
STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
STR_ORDER_DROP_UNLOAD,
STR_ORDER_DROP_TRANSFER,
STR_EMPTY,
STR_ORDER_DROP_NO_UNLOADING,
INVALID_STRING_ID
};
static const StringID _order_goto_dropdown[] = {
STR_ORDER_GO_TO,
STR_ORDER_GO_TO_NEAREST_DEPOT,
STR_ORDER_CONDITIONAL,
INVALID_STRING_ID
};
static const StringID _order_goto_dropdown_aircraft[] = {
STR_ORDER_GO_TO,
STR_ORDER_GO_TO_NEAREST_HANGAR,
STR_ORDER_CONDITIONAL,
INVALID_STRING_ID
};
static const StringID _order_conditional_variable[] = {
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE,
STR_ORDER_CONDITIONAL_RELIABILITY,
STR_ORDER_CONDITIONAL_MAX_SPEED,
STR_ORDER_CONDITIONAL_AGE,
STR_ORDER_CONDITIONAL_REQUIRES_SERVICE,
STR_ORDER_CONDITIONAL_UNCONDITIONALLY,
INVALID_STRING_ID,
};
static const StringID _order_conditional_condition[] = {
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
INVALID_STRING_ID,
};
extern uint ConvertSpeedToDisplaySpeed(uint speed);
extern uint ConvertDisplaySpeedToSpeed(uint speed);
static const StringID _order_depot_action_dropdown[] = {
STR_ORDER_DROP_GO_ALWAYS_DEPOT,
STR_ORDER_DROP_SERVICE_DEPOT,
STR_ORDER_DROP_HALT_DEPOT,
INVALID_STRING_ID
};
static int DepotActionStringIndex(const Order *order)
{
if (order->GetDepotActionType() & ODATFB_HALT) {
return DA_STOP;
} else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
return DA_SERVICE;
} else {
return DA_ALWAYS_GO;
}
}
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int width)
{
StringID str = (v->cur_order_index == order_index) ? STR_ORDER_SELECTED : STR_ORDER;
SetDParam(6, STR_EMPTY);
switch (order->GetType()) {
case OT_DUMMY:
SetDParam(1, STR_INVALID_ORDER);
SetDParam(2, order->GetDestination());
break;
case OT_GOTO_STATION: {
OrderLoadFlags load = order->GetLoadType();
OrderUnloadFlags unload = order->GetUnloadType();
SetDParam(1, STR_GO_TO_STATION);
SetDParam(2, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0));
SetDParam(3, order->GetDestination());
if (timetable) {
SetDParam(4, STR_EMPTY);
if (order->wait_time > 0) {
SetDParam(6, STR_TIMETABLE_STAY_FOR);
SetTimetableParams(7, 8, order->wait_time);
}
} else {
SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]);
if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
SetDParam(6, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
}
}
} break;
case OT_GOTO_DEPOT:
if (v->type == VEH_AIRCRAFT) {
if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
SetDParam(1, STR_GO_TO_NEAREST_DEPOT);
SetDParam(3, STR_ORDER_NEAREST_HANGAR);
} else {
SetDParam(1, STR_GO_TO_HANGAR);
SetDParam(3, order->GetDestination());
}
SetDParam(4, STR_EMPTY);
} else {
if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
SetDParam(1, STR_GO_TO_NEAREST_DEPOT);
SetDParam(3, STR_ORDER_NEAREST_DEPOT);
} else {
SetDParam(1, STR_GO_TO_DEPOT);
SetDParam(3, GetDepot(order->GetDestination())->town_index);
}
switch (v->type) {
case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break;
case VEH_ROAD: SetDParam(4, STR_ORDER_ROAD_DEPOT); break;
case VEH_SHIP: SetDParam(4, STR_ORDER_SHIP_DEPOT); break;
default: NOT_REACHED();
}
}
if (order->GetDepotOrderType() & ODTFB_SERVICE) {
SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
} else {
SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
}
if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
SetDParam(6, STR_STOP_ORDER);
}
if (!timetable && order->IsRefit()) {
SetDParam(6, (order->GetDepotActionType() & ODATFB_HALT) ? STR_REFIT_STOP_ORDER : STR_REFIT_ORDER);
SetDParam(7, GetCargo(order->GetRefitCargo())->name);
}
break;
case OT_GOTO_WAYPOINT:
SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
SetDParam(2, order->GetDestination());
break;
case OT_CONDITIONAL:
SetDParam(2, order->GetConditionSkipToOrder() + 1);
if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL);
} else {
OrderConditionComparator occ = order->GetConditionComparator();
SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM);
SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(5, value);
}
if (timetable && order->wait_time > 0) {
SetDParam(6, STR_TIMETABLE_AND_TRAVEL_FOR);
SetTimetableParams(7, 8, order->wait_time);
} else {
SetDParam(6, STR_EMPTY);
}
break;
default: NOT_REACHED();
}
SetDParam(0, order_index + 1);
DrawString(2, width + 2, y, str, selected ? TC_WHITE : TC_BLACK);
}
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
{
Order order;
order.next = NULL;
order.index = 0;
/* check depot first */
if (_settings_game.order.gotodepot) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
if (IsRailDepot(tile)) {
order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
return order;
}
}
break;
case MP_ROAD:
if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
return order;
}
break;
case MP_STATION:
if (v->type != VEH_AIRCRAFT) break;
if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS);
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
return order;
}
break;
case MP_WATER:
if (v->type != VEH_SHIP) break;
if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
TileIndex tile2 = GetOtherShipDepotTile(tile);
order.MakeGoToDepot(GetDepotByTile(tile < tile2 ? tile : tile2)->index, ODTFB_PART_OF_ORDERS);
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
return order;
}
default:
break;
}
}
/* check waypoint */
if (IsRailWaypointTile(tile) &&
v->type == VEH_TRAIN &&
IsTileOwner(tile, _local_company)) {
order.MakeGoToWaypoint(GetWaypointByTile(tile)->index);
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
return order;
}
if (IsTileType(tile, MP_STATION)) {
StationID st_index = GetStationIndex(tile);
const Station *st = GetStation(st_index);
if (st->owner == _local_company || st->owner == OWNER_NONE) {
byte facil;
(facil = FACIL_DOCK, v->type == VEH_SHIP) ||
(facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
(facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
(facil = FACIL_BUS_STOP, v->type == VEH_ROAD && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) ||
(facil = FACIL_TRUCK_STOP, 1);
if (st->facilities & facil) {
order.MakeGoToStation(st_index);
if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
if (_settings_client.gui.new_nonstop && (v->type == VEH_TRAIN || v->type == VEH_ROAD)) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
return order;
}
}
}
/* not found */
order.Free();
return order;
}
/** Order window code. */
struct OrdersWindow : public Window {
private:
static const int ORDER_LIST_LINE_HEIGHT = 10; ///< Height of a line in the ORDER_WIDGET_ORDER_LIST panel.
/** Under what reason are we using the PlaceObject functionality? */
enum OrderPlaceObjectState {
OPOS_GOTO,
OPOS_CONDITIONAL,
};
int selected_order;
OrderPlaceObjectState goto_type;
const Vehicle *vehicle;
/**
* Return the memorised selected order.
* @return the memorised order if it is a vaild one
* else return the number of orders
*/
int OrderGetSel()
{
int num = this->selected_order;
return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
}
/**
* Calculate the selected order.
* The calculation is based on the relative (to the window) y click position and
* the position of the scrollbar.
*
* @param y Y-value of the click relative to the window origin
* @return The selected order if the order is valid, else return \c INVALID_ORDER.
*/
int GetOrderFromPt(int y)
{
int sel = (y - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / ORDER_LIST_LINE_HEIGHT; // Selected line in the ORDER_WIDGET_ORDER_LIST panel.
if ((uint)sel >= this->vscroll.cap) return INVALID_ORDER;
sel += this->vscroll.pos;
return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_ORDER;
}
bool HandleOrderVehClick(const Vehicle *u)
{
if (u->type != this->vehicle->type) return false;
if (!u->IsPrimaryVehicle()) {
u = u->First();
if (!u->IsPrimaryVehicle()) return false;
}
/* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
* obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */
if (this->vehicle->GetNumOrders() != 0 && _ctrl_pressed == 0) return false;
if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY,
_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
this->selected_order = -1;
ResetObjectToPlace();
}
return true;
}
/**
* Handle the click on the goto button.
*
* @param w current window
*/
static void OrderClick_Goto(OrdersWindow *w, int i)
{
w->InvalidateWidget(ORDER_WIDGET_GOTO);
w->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO);
if (w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
_place_clicked_vehicle = NULL;
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT, w);
w->goto_type = OPOS_GOTO;
} else {
ResetObjectToPlace();
}
}
/**
* Handle the click on the full load button.
*
* @param w current window
* @param load_type the way to load.
*/
static void OrderClick_FullLoad(OrdersWindow *w, int load_type)
{
VehicleOrderID sel_ord = w->OrderGetSel();
const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
if (order == NULL || order->GetLoadType() == load_type) return;
if (load_type < 0) {
load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
}
DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
/**
* Handle the click on the service.
*
* @param w current window
*/
static void OrderClick_Service(OrdersWindow *w, int i)
{
VehicleOrderID sel_ord = w->OrderGetSel();
if (i < 0) {
const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
if (order == NULL) return;
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
}
DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
/**
* Handle the click on the service in nearest depot button.
*
* @param w current window
*/
static void OrderClick_NearestDepot(OrdersWindow *w, int i)
{
Order order;
order.next = NULL;
order.index = 0;
order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS);
order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
}
/**
* Handle the click on the conditional order button.
*
* @param w current window
*/
static void OrderClick_Conditional(OrdersWindow *w, int i)
{
w->InvalidateWidget(ORDER_WIDGET_GOTO);
w->LowerWidget(ORDER_WIDGET_GOTO);
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT, w);
w->goto_type = OPOS_CONDITIONAL;
}
/**
* Handle the click on the unload button.
*
* @param w current window
*/
static void OrderClick_Unload(OrdersWindow *w, int unload_type)
{
VehicleOrderID sel_ord = w->OrderGetSel();
const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
if (order == NULL || order->GetUnloadType() == unload_type) return;
if (unload_type < 0) {
unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
}
DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
/**
* Handle the click on the nonstop button.
*
* @param w current window
* @param non_stop what non-stop type to use; -1 to use the 'next' one.
*/
static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
{
VehicleOrderID sel_ord = w->OrderGetSel();
const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
if (order == NULL || order->GetNonStopType() == non_stop) return;
/* Keypress if negative, so 'toggle' to the next */
if (non_stop < 0) {
non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
}
w->InvalidateWidget(ORDER_WIDGET_NON_STOP);
DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
/**
* Handle the click on the skip button.
* If ctrl is pressed skip to selected order.
* Else skip to current order + 1
*
* @param w current window
*/
static void OrderClick_Skip(OrdersWindow *w, int i)
{
/* Don't skip when there's nothing to skip */
if (_ctrl_pressed && w->vehicle->cur_order_index == w->OrderGetSel()) return;
if (w->vehicle->GetNumOrders() <= 1) return;
DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->GetNumOrders()),
CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
}
/**
* Handle the click on the delete button.
*
* @param w current window
*/
static void OrderClick_Delete(OrdersWindow *w, int i)
{
/* When networking, move one order lower */
int selected = w->selected_order + (int)_networking;
if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
w->selected_order = selected >= w->vehicle->GetNumOrders() ? -1 : selected;
}
}
/**
* Handle the click on the refit button.
* If ctrl is pressed cancel refitting.
* Else show the refit window.
*
* @param w current window
*/
static void OrderClick_Refit(OrdersWindow *w, int i)
{
if (_ctrl_pressed) {
/* Cancel refitting */
DoCommandP(w->vehicle->tile, w->vehicle->index, (w->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
} else {
ShowVehicleRefitWindow(w->vehicle, w->OrderGetSel(), w);
}
}
typedef void Handler(OrdersWindow*, int);
struct KeyToEvent {
uint16 keycode;
Handler *proc;
};
public:
OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window(desc, v->index)
{
int num_lines = (this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / ORDER_LIST_LINE_HEIGHT;
/* Verify that the order panel is *exactly* of the right size. */
assert(this->widget[ORDER_WIDGET_ORDER_LIST].top + 1 + num_lines * ORDER_LIST_LINE_HEIGHT == this->widget[ORDER_WIDGET_ORDER_LIST].bottom);
this->owner = v->owner;
this->vscroll.cap = num_lines;
this->resize.step_height = ORDER_LIST_LINE_HEIGHT;
this->selected_order = -1;
this->vehicle = v;
if (_settings_client.gui.quick_goto && v->owner == _local_company) {
/* If there are less than 2 station, make Go To active. */
int station_orders = 0;
const Order *order;
FOR_VEHICLE_ORDERS(v, order) {
if (order->IsType(OT_GOTO_STATION)) station_orders++;
}
if (station_orders < 2) OrderClick_Goto(this, 0);
}
if (_settings_game.order.timetabling) {
this->widget[ORDER_WIDGET_CAPTION].right -= 61;
} else {
this->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
}
this->FindWindowPlacementAndResize(desc);
}
virtual void OnInvalidateData(int data)
{
switch (data) {
case 0:
/* Autoreplace replaced the vehicle */
this->vehicle = GetVehicle(this->window_number);
break;
case -1:
/* Removed / replaced all orders (after deleting / sharing) */
if (this->selected_order == -1) break;
this->DeleteChildWindows();
HideDropDownMenu(this);
this->selected_order = -1;
break;
default: {
/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
* the order is being created / removed */
if (this->selected_order == -1) break;
VehicleOrderID from = GB(data, 0, 8);
VehicleOrderID to = GB(data, 8, 8);
if (from == to) break; // no need to change anything
if (from != this->selected_order) {
/* Moving from preceeding order? */
this->selected_order -= (int)(from <= this->selected_order);
/* Moving to preceeding order? */
this->selected_order += (int)(to <= this->selected_order);
break;
}
/* Now we are modifying the selected order */
if (to == INVALID_VEH_ORDER_ID) {
/* Deleting selected order */
this->DeleteChildWindows();
HideDropDownMenu(this);
this->selected_order = -1;
break;
}
/* Moving selected order */
this->selected_order = to;
} break;
}
}
virtual void OnPaint()
{
bool shared_orders = this->vehicle->IsOrderListShared();
SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
int sel = OrderGetSel();
const Order *order = GetVehicleOrder(this->vehicle, sel);
if (this->vehicle->owner == _local_company) {
/* Set the strings for the dropdown boxes. */
this->widget[ORDER_WIDGET_COND_VARIABLE].data = _order_conditional_variable[order == NULL ? 0 : order->GetConditionVariable()];
this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
/* skip */
this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1);
/* delete */
this->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
(uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
/* non-stop only for trains */
this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP, (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) || order == NULL);
this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_NON_STOP));
this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_FULL_LOAD));
this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_UNLOAD));
/* Disable list of vehicles with the same shared orders if there is no list */
this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
this->SetWidgetDisabledState(ORDER_WIDGET_REFIT, order == NULL); // Refit
this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE, order == NULL); // Service
this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE_DROPDOWN, order == NULL); // Service
this->HideWidget(ORDER_WIDGET_REFIT); // Refit
this->HideWidget(ORDER_WIDGET_SERVICE); // Service
this->HideWidget(ORDER_WIDGET_SERVICE_DROPDOWN); // Service
this->HideWidget(ORDER_WIDGET_COND_VARIABLE);
this->HideWidget(ORDER_WIDGET_COND_COMPARATOR);
this->HideWidget(ORDER_WIDGET_COND_VALUE);
}
this->ShowWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
this->ShowWidget(ORDER_WIDGET_NON_STOP);
this->ShowWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
this->ShowWidget(ORDER_WIDGET_UNLOAD);
this->ShowWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
this->ShowWidget(ORDER_WIDGET_FULL_LOAD);
this->RaiseWidget(ORDER_WIDGET_NON_STOP);
this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
this->RaiseWidget(ORDER_WIDGET_UNLOAD);
this->RaiseWidget(ORDER_WIDGET_SERVICE);
if (order != NULL) {
this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
switch (order->GetType()) {
case OT_GOTO_STATION:
if (!GetStation(order->GetDestination())->IsBuoy()) {
this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
break;
}
/* Fall-through */
case OT_GOTO_WAYPOINT:
this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
this->DisableWidget(ORDER_WIDGET_UNLOAD);
break;
case OT_GOTO_DEPOT:
/* Remove unload and replace it with refit */
this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
this->HideWidget(ORDER_WIDGET_UNLOAD);
this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
this->HideWidget(ORDER_WIDGET_FULL_LOAD);
this->ShowWidget(ORDER_WIDGET_REFIT);
this->ShowWidget(ORDER_WIDGET_SERVICE_DROPDOWN);
this->ShowWidget(ORDER_WIDGET_SERVICE);
this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
break;
case OT_CONDITIONAL: {
this->HideWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
this->HideWidget(ORDER_WIDGET_NON_STOP);
this->HideWidget(ORDER_WIDGET_UNLOAD);
this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
this->HideWidget(ORDER_WIDGET_FULL_LOAD);
this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
this->ShowWidget(ORDER_WIDGET_COND_VARIABLE);
this->ShowWidget(ORDER_WIDGET_COND_COMPARATOR);
this->ShowWidget(ORDER_WIDGET_COND_VALUE);
OrderConditionVariable ocv = order->GetConditionVariable();
this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(1, value);
} break;
default: // every other orders
this->DisableWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
this->DisableWidget(ORDER_WIDGET_NON_STOP);
this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
this->DisableWidget(ORDER_WIDGET_UNLOAD);
}
}
SetDParam(0, this->vehicle->index);
this->DrawWidgets();
int y = 15;
int i = this->vscroll.pos;
order = GetVehicleOrder(this->vehicle, i);
StringID str;
while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */
if (i - this->vscroll.pos >= this->vscroll.cap) break;
DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, this->widget[ORDER_WIDGET_ORDER_LIST].right - 4);
y += ORDER_LIST_LINE_HEIGHT;
i++;
order = order->next;
}
if (i - this->vscroll.pos < this->vscroll.cap) {
str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
DrawString(this->widget[ORDER_WIDGET_ORDER_LIST].left + 2, this->widget[ORDER_WIDGET_ORDER_LIST].right - 2, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
}
}
virtual void OnClick(Point pt, int widget)
{
switch (widget) {
case ORDER_WIDGET_ORDER_LIST: {
ResetObjectToPlace();
int sel = this->GetOrderFromPt(pt.y);
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
const Order *ord = GetVehicleOrder(this->vehicle, sel);
TileIndex xy = INVALID_TILE;
switch (ord->GetType()) {
case OT_GOTO_STATION: xy = GetStation(ord->GetDestination())->xy ; break;
case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->GetDestination())->xy; break;
case OT_GOTO_DEPOT:
if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
xy = (this->vehicle->type == VEH_AIRCRAFT) ? GetStation(ord->GetDestination())->xy : GetDepot(ord->GetDestination())->xy;
break;
default:
break;
}
if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
return;
}
/* This order won't be selected any more, close all child windows and dropdowns */
this->DeleteChildWindows();
HideDropDownMenu(this);
if (sel == INVALID_ORDER) {
/* Deselect clicked order */
this->selected_order = -1;
} else if (sel == this->selected_order) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
MOF_STOP_LOCATION | ((GetVehicleOrder(this->vehicle, sel)->GetStopLocation() + 1) % OSL_END) << 4,
CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
} else {
/* Select clicked order */
this->selected_order = sel;
if (this->vehicle->owner == _local_company) {
/* Activate drag and drop */
SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
}
}
this->SetDirty();
} break;
case ORDER_WIDGET_SKIP:
OrderClick_Skip(this, 0);
break;
case ORDER_WIDGET_DELETE:
OrderClick_Delete(this, 0);
break;
case ORDER_WIDGET_NON_STOP:
OrderClick_Nonstop(this, -1);
break;
case ORDER_WIDGET_NON_STOP_DROPDOWN: {
const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP_DROPDOWN, 0, o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
} break;
case ORDER_WIDGET_GOTO:
OrderClick_Goto(this, 0);
break;
case ORDER_WIDGET_GOTO_DROPDOWN:
ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO_DROPDOWN, 0, 0);
break;
case ORDER_WIDGET_FULL_LOAD:
OrderClick_FullLoad(this, -1);
break;
case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
ShowDropDownMenu(this, _order_full_load_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
break;
case ORDER_WIDGET_UNLOAD:
OrderClick_Unload(this, -1);
break;
case ORDER_WIDGET_UNLOAD_DROPDOWN:
ShowDropDownMenu(this, _order_unload_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
break;
case ORDER_WIDGET_REFIT:
OrderClick_Refit(this, 0);
break;
case ORDER_WIDGET_SERVICE:
OrderClick_Service(this, -1);
break;
case ORDER_WIDGET_SERVICE_DROPDOWN:
ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
break;
case ORDER_WIDGET_TIMETABLE_VIEW:
ShowTimetableWindow(this->vehicle);
break;
case ORDER_WIDGET_COND_VARIABLE:
ShowDropDownMenu(this, _order_conditional_variable, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
break;
case ORDER_WIDGET_COND_COMPARATOR: {
const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
} break;
case ORDER_WIDGET_COND_VALUE: {
const Order *order = GetVehicleOrder(this->vehicle, this->OrderGetSel());
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(0, value);
ShowQueryString(STR_CONFIG_SETTING_INT32, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
} break;
case ORDER_WIDGET_SHARED_ORDER_LIST:
ShowVehicleListWindow(this->vehicle);
break;
}
}
virtual void OnQueryTextFinished(char *str)
{
if (!StrEmpty(str)) {
VehicleOrderID sel = this->OrderGetSel();
uint value = atoi(str);
switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) {
case OCV_MAX_SPEED:
value = ConvertDisplaySpeedToSpeed(value);
break;
case OCV_RELIABILITY:
case OCV_LOAD_PERCENTAGE:
value = Clamp(value, 0, 100);
default:
break;
}
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
}
virtual void OnDropdownSelect(int widget, int index)
{
switch (widget) {
case ORDER_WIDGET_NON_STOP_DROPDOWN:
OrderClick_Nonstop(this, index);
break;
case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
OrderClick_FullLoad(this, index);
break;
case ORDER_WIDGET_UNLOAD_DROPDOWN:
OrderClick_Unload(this, index);
break;
case ORDER_WIDGET_GOTO_DROPDOWN:
switch (index) {
case 0: OrderClick_Goto(this, 0); break;
case 1: OrderClick_NearestDepot(this, 0); break;
case 2: OrderClick_Conditional(this, 0); break;
default: NOT_REACHED();
}
break;
case ORDER_WIDGET_SERVICE_DROPDOWN:
OrderClick_Service(this, index);
break;
case ORDER_WIDGET_COND_VARIABLE:
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
break;
case ORDER_WIDGET_COND_COMPARATOR:
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_COMPARATOR | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
break;
}
}
virtual void OnDragDrop(Point pt, int widget)
{
switch (widget) {
case ORDER_WIDGET_ORDER_LIST: {
int from_order = this->OrderGetSel();
int to_order = this->GetOrderFromPt(pt.y);
if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
this->selected_order = -1;
}
} break;
case ORDER_WIDGET_DELETE:
OrderClick_Delete(this, 0);
break;
}
ResetObjectToPlace();
}
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
static const KeyToEvent keytoevent[] = {
{'D', OrderClick_Skip},
{'F', OrderClick_Delete},
{'G', OrderClick_Goto},
{'H', OrderClick_Nonstop},
{'J', OrderClick_FullLoad},
{'K', OrderClick_Unload},
//('?', OrderClick_Service},
};
if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
for (uint i = 0; i < lengthof(keytoevent); i++) {
if (keycode == keytoevent[i].keycode) {
keytoevent[i].proc(this, -1);
return ES_HANDLED;
}
}
return ES_NOT_HANDLED;
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
{
if (this->goto_type == OPOS_GOTO) {
/* check if we're clicking on a vehicle first.. clone orders in that case. */
const Vehicle *v = CheckMouseOverVehicle();
if (v != NULL && this->HandleOrderVehClick(v)) return;
const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
if (!cmd.IsValid()) return;
if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
/* With quick goto the Go To button stays active */
if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
}
}
}
virtual void OnPlaceObjectAbort()
{
if (this->goto_type == OPOS_CONDITIONAL) {
this->goto_type = OPOS_GOTO;
if (_cursor.pos.x >= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].left) &&
_cursor.pos.y >= (this->top + this->widget[ORDER_WIDGET_ORDER_LIST].top) &&
_cursor.pos.x <= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].right) &&
_cursor.pos.y <= (this->top + this->widget[ORDER_WIDGET_ORDER_LIST].bottom)) {
int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
if (order_id != INVALID_ORDER) {
Order order;
order.next = NULL;
order.index = 0;
order.MakeConditional(order_id);
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
}
}
}
this->RaiseWidget(ORDER_WIDGET_GOTO);
this->InvalidateWidget(ORDER_WIDGET_GOTO);
}
virtual void OnMouseLoop()
{
const Vehicle *v = _place_clicked_vehicle;
/*
* Check if we clicked on a vehicle
* and if the GOTO button of this window is pressed
* This is because of all open order windows WE_MOUSELOOP is called
* and if you have 3 windows open, and this check is not done
* the order is copied to the last open window instead of the
* one where GOTO is enabled
*/
if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
_place_clicked_vehicle = NULL;
this->HandleOrderVehClick(v);
}
}
/**
* Set the left and right edge of a widget in the window.
* @param widnum Number of the widget to modify.
* @param left New offset of the left edge of the widget.
* @param right New offset of the right edge of the widget.
*/
void SetWidgetLeftRight(int widnum, int left, int right)
{
assert(this->widget[widnum].type != WWT_EMPTY);
this->widget[widnum].left = left;
this->widget[widnum].right = right;
}
virtual void OnResize(Point delta)
{
/* Update the scroll + matrix */
this->vscroll.cap = (this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / ORDER_LIST_LINE_HEIGHT;
/* Update the button bars. */
if (this->vehicle->owner == _local_company) {
const int arrow_width = 12; // Space needed by the down arrow.
/* ORDER_WIDGET_ORDER_LIST widget has the same left and right positions as the whole button bars. */
const int leftmost = this->widget[ORDER_WIDGET_ORDER_LIST].left; // The left edge of the button bar.
const int rightmost = this->widget[ORDER_WIDGET_ORDER_LIST].right + 1; // One pixel beyond the right edge of the button bar.
const int one_third = leftmost + (rightmost - leftmost) / 3; // Start of the middle section.
const int two_third = one_third + (rightmost - one_third) / 2; // Start of the right section.
/* Left 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_SKIP, leftmost, one_third - 1);
SetWidgetLeftRight(ORDER_WIDGET_COND_VARIABLE, leftmost, one_third - 1);
/* Middle 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_DELETE, one_third, two_third - 1);
SetWidgetLeftRight(ORDER_WIDGET_COND_COMPARATOR, one_third, two_third - 1);
/* Right 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_GOTO_DROPDOWN, two_third, rightmost - 1);
SetWidgetLeftRight(ORDER_WIDGET_GOTO, two_third, rightmost - 1 - arrow_width);
SetWidgetLeftRight(ORDER_WIDGET_COND_VALUE, two_third, rightmost - 1);
if (this->vehicle->type == VEH_TRAIN || this->vehicle->type == VEH_ROAD) {
/* Window displays orders of your train/road vehicle. */
/* Left 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_NON_STOP_DROPDOWN, leftmost, one_third - 1);
SetWidgetLeftRight(ORDER_WIDGET_NON_STOP, leftmost, one_third - 1 - arrow_width);
/* Middle 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_FULL_LOAD_DROPDOWN, one_third, two_third - 1);
SetWidgetLeftRight(ORDER_WIDGET_FULL_LOAD, one_third, two_third - 1 - arrow_width);
SetWidgetLeftRight(ORDER_WIDGET_REFIT, one_third, two_third - 1);
/* Right 1/3 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_UNLOAD_DROPDOWN, two_third, rightmost - 1);
SetWidgetLeftRight(ORDER_WIDGET_UNLOAD, two_third, rightmost - 1 - arrow_width);
SetWidgetLeftRight(ORDER_WIDGET_SERVICE_DROPDOWN, two_third, rightmost - 1);
SetWidgetLeftRight(ORDER_WIDGET_SERVICE, two_third, rightmost - 1 - arrow_width);
} else {
/* Window displays orders of your ship/plane vehicle. */
const int middle = (rightmost - leftmost) / 2; // Start of second half.
/* Left 1/2 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_FULL_LOAD_DROPDOWN, leftmost, middle - 1);
SetWidgetLeftRight(ORDER_WIDGET_FULL_LOAD, leftmost, middle - 1 - arrow_width);
SetWidgetLeftRight(ORDER_WIDGET_REFIT, leftmost, middle - 1);
/* Right 1/2 buttons. */
SetWidgetLeftRight(ORDER_WIDGET_UNLOAD_DROPDOWN, middle, rightmost - 1);
SetWidgetLeftRight(ORDER_WIDGET_UNLOAD, middle, rightmost - 1 - arrow_width);
SetWidgetLeftRight(ORDER_WIDGET_SERVICE_DROPDOWN, middle, rightmost - 1);
SetWidgetLeftRight(ORDER_WIDGET_SERVICE, middle, rightmost - 1 - arrow_width);
}
}
}
virtual void OnTimeout()
{
/* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
for (uint i = 0; i < this->widget_count; i++) {
if (this->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
this->RaiseWidget(i);
this->InvalidateWidget(i);
}
}
}
};
/**
* Widget definition for "your" train orders
*/
static const Widget _orders_train_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 371, 0, 13, STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_GREY, 311, 371, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 372, 383, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // ORDER_WIDGET_STICKY
{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 371, 14, 75, 0x0, STR_ORDERS_LIST_TOOLTIP}, // ORDER_WIDGET_ORDER_LIST
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 372, 383, 14, 75, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 123, 88, 99, STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP}, // ORDER_WIDGET_SKIP
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 124, 247, 88, 99, STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP}, // ORDER_WIDGET_DELETE
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 0, 123, 76, 87, STR_NULL, STR_ORDER_TOOLTIP_NON_STOP}, // ORDER_WIDGET_NON_STOP_DROPDOWN
{ WWT_TEXTBTN, RESIZE_TB, COLOUR_GREY, 0, 111, 76, 87, STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP}, // ORDER_WIDGET_NON_STOP
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 248, 371, 88, 99, STR_EMPTY, STR_ORDER_GO_TO_DROPDOWN_TOOLTIP}, // ORDER_WIDGET_GOTO_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 359, 88, 99, STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP}, // ORDER_WIDGET_GOTO
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 124, 247, 76, 87, STR_NULL, STR_ORDER_TOOLTIP_FULL_LOAD}, // ORDER_WIDGET_FULL_LOAD_DROPDOWN
{ WWT_TEXTBTN, RESIZE_TB, COLOUR_GREY, 124, 235, 76, 87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD}, // ORDER_WIDGET_FULL_LOAD
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 248, 371, 76, 87, STR_NULL, STR_ORDER_TOOLTIP_UNLOAD}, // ORDER_WIDGET_UNLOAD_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 359, 76, 87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD}, // ORDER_WIDGET_UNLOAD
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 124, 247, 76, 87, STR_REFIT, STR_REFIT_TIP}, // ORDER_WIDGET_REFIT
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 248, 371, 76, 87, STR_NULL, STR_SERVICE_HINT}, // ORDER_WIDGET_SERVICE_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 359, 76, 87, STR_SERVICE, STR_SERVICE_HINT}, // ORDER_WIDGET_SERVICE
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 0, 123, 76, 87, STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP}, // ORDER_WIDGET_COND_VARIABLE
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 124, 247, 76, 87, STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 371, 76, 87, STR_CONDITIONAL_VALUE, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP}, // ORDER_WIDGET_COND_VALUE
{ WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 372, 383, 76, 87, SPR_SHARED_ORDERS_ICON, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 372, 383, 88, 99, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
{ WIDGETS_END},
};
static const WindowDesc _orders_train_desc(
WDP_AUTO, WDP_AUTO, 384, 100, 384, 100,
WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_orders_train_widgets
);
/**
* Widget definition for "your" orders (!train)
*/
static const Widget _orders_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 371, 0, 13, STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_GREY, 311, 371, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 372, 383, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // ORDER_WIDGET_STICKY
{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 371, 14, 75, 0x0, STR_ORDERS_LIST_TOOLTIP}, // ORDER_WIDGET_ORDER_LIST
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 372, 383, 14, 75, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 123, 88, 99, STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP}, // ORDER_WIDGET_SKIP
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 124, 247, 88, 99, STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP}, // ORDER_WIDGET_DELETE
{ WWT_EMPTY, RESIZE_TB, COLOUR_GREY, 0, 0, 76, 87, 0x0, 0x0}, // ORDER_WIDGET_NON_STOP_DROPDOWN
{ WWT_EMPTY, RESIZE_TB, COLOUR_GREY, 0, 0, 76, 87, 0x0, 0x0}, // ORDER_WIDGET_NON_STOP
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 248, 371, 88, 99, STR_EMPTY, STR_ORDER_GO_TO_DROPDOWN_TOOLTIP}, // ORDER_WIDGET_GOTO_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 359, 88, 99, STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP}, // ORDER_WIDGET_GOTO
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 0, 185, 76, 87, STR_NULL, STR_ORDER_TOOLTIP_FULL_LOAD}, // ORDER_WIDGET_FULL_LOAD_DROPDOWN
{ WWT_TEXTBTN, RESIZE_TB, COLOUR_GREY, 0, 173, 76, 87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD}, // ORDER_WIDGET_FULL_LOAD
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 186, 371, 76, 87, STR_NULL, STR_ORDER_TOOLTIP_UNLOAD}, // ORDER_WIDGET_UNLOAD_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 186, 359, 76, 87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD}, // ORDER_WIDGET_UNLOAD
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 185, 76, 87, STR_REFIT, STR_REFIT_TIP}, // ORDER_WIDGET_REFIT
{ WWT_DROPDOWN, RESIZE_RTB, COLOUR_GREY, 186, 371, 76, 87, STR_NULL, STR_SERVICE_HINT}, // ORDER_WIDGET_SERVICE_DROPDOWN
{ WWT_TEXTBTN, RESIZE_RTB, COLOUR_GREY, 186, 359, 76, 87, STR_SERVICE, STR_SERVICE_HINT}, // ORDER_WIDGET_SERVICE
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 0, 123, 76, 87, STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP}, // ORDER_WIDGET_COND_VARIABLE
{ WWT_DROPDOWN, RESIZE_TB, COLOUR_GREY, 124, 247, 76, 87, STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 248, 371, 76, 87, STR_CONDITIONAL_VALUE, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP}, // ORDER_WIDGET_COND_VALUE
{ WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 372, 383, 76, 87, SPR_SHARED_ORDERS_ICON, STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 372, 383, 88, 99, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
{ WIDGETS_END},
};
static const WindowDesc _orders_desc(
WDP_AUTO, WDP_AUTO, 384, 100, 384, 100,
WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_orders_widgets
);
/**
* Widget definition for competitor orders
*/
static const Widget _other_orders_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 371, 0, 13, STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS}, // ORDER_WIDGET_CAPTION
{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_GREY, 311, 371, 0, 13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP}, // ORDER_WIDGET_TIMETABLE_VIEW
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 372, 383, 0, 13, STR_NULL, STR_STICKY_BUTTON}, // ORDER_WIDGET_STICKY
{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 371, 14, 85, 0x0, STR_ORDERS_LIST_TOOLTIP}, // ORDER_WIDGET_ORDER_LIST
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 372, 383, 14, 73, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST}, // ORDER_WIDGET_SCROLLBAR
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SKIP
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_DELETE
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_NON_STOP_DROPDOWN
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_NON_STOP
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_GOTO_DROPDOWN
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_GOTO
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_FULL_LOAD_DROPDOWN
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_FULL_LOAD
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_UNLOAD_DROPDOWN
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_UNLOAD
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_REFIT
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SERVICE_DROPDOWN
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SERVICE
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_COND_VARIABLE
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_COND_COMPARATOR
{ WWT_EMPTY, RESIZE_NONE, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_COND_VALUE
{ WWT_EMPTY, RESIZE_TB, COLOUR_GREY, 0, 0, 76, 87, 0x0, STR_NULL}, // ORDER_WIDGET_SHARED_ORDER_LIST
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 372, 383, 74, 85, 0x0, STR_RESIZE_BUTTON}, // ORDER_WIDGET_RESIZE
{ WIDGETS_END},
};
static const WindowDesc _other_orders_desc(
WDP_AUTO, WDP_AUTO, 384, 86, 384, 86,
WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE | WDF_CONSTRUCTION,
_other_orders_widgets
);
void ShowOrdersWindow(const Vehicle *v)
{
DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
if (v->owner != _local_company) {
new OrdersWindow(&_other_orders_desc, v);
} else {
new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
}
}
|