# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 15723 2009-03-15 15:12:06Z rubidium $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "station_map.h"
    00007 #include "window_gui.h"
    00008 #include "command_func.h"
    00009 #include "viewport_func.h"
    00010 #include "gfx_func.h"
    00011 #include "depot_base.h"
    00012 #include "vehicle_base.h"
    00013 #include "vehicle_gui.h"
    00014 #include "timetable.h"
    00015 #include "cargotype.h"
    00016 #include "strings_func.h"
    00017 #include "window_func.h"
    00018 #include "vehicle_func.h"
    00019 #include "company_func.h"
    00020 #include "newgrf_cargo.h"
    00021 #include "widgets/dropdown_func.h"
    00022 #include "textbuf_gui.h"
    00023 #include "string_func.h"
    00024 #include "tilehighlight_func.h"
    00025 #include "network/network.h"
    00026 #include "settings_type.h"
    00027
    00028 #include "table/sprites.h"
    00029 #include "table/strings.h"
    00030
    00031 enum OrderWindowWidgets {
    00032   ORDER_WIDGET_CLOSEBOX = 0,
    00033   ORDER_WIDGET_CAPTION,
    00034   ORDER_WIDGET_TIMETABLE_VIEW,
    00035   ORDER_WIDGET_STICKY,
    00036   ORDER_WIDGET_ORDER_LIST,
    00037   ORDER_WIDGET_SCROLLBAR,
    00038   ORDER_WIDGET_SKIP,
    00039   ORDER_WIDGET_DELETE,
    00040   ORDER_WIDGET_NON_STOP_DROPDOWN,
    00041   ORDER_WIDGET_NON_STOP,
    00042   ORDER_WIDGET_GOTO_DROPDOWN,
    00043   ORDER_WIDGET_GOTO,
    00044   ORDER_WIDGET_FULL_LOAD_DROPDOWN,
    00045   ORDER_WIDGET_FULL_LOAD,
    00046   ORDER_WIDGET_UNLOAD_DROPDOWN,
    00047   ORDER_WIDGET_UNLOAD,
    00048   ORDER_WIDGET_REFIT,
    00049   ORDER_WIDGET_SERVICE_DROPDOWN,
    00050   ORDER_WIDGET_SERVICE,
    00051   ORDER_WIDGET_COND_VARIABLE,
    00052   ORDER_WIDGET_COND_COMPARATOR,
    00053   ORDER_WIDGET_COND_VALUE,
    00054   ORDER_WIDGET_RESIZE_BAR,
    00055   ORDER_WIDGET_SHARED_ORDER_LIST,
    00056   ORDER_WIDGET_RESIZE,
    00057 };
    00058
    00060 static const StringID _station_load_types[][5] = {
    00061   {
    00062     STR_EMPTY,
    00063     INVALID_STRING_ID,
    00064     STR_ORDER_FULL_LOAD,
    00065     STR_ORDER_FULL_LOAD_ANY,
    00066     STR_ORDER_NO_LOAD,
    00067   }, {
    00068     STR_ORDER_UNLOAD,
    00069     INVALID_STRING_ID,
    00070     STR_ORDER_UNLOAD_FULL_LOAD,
    00071     STR_ORDER_UNLOAD_FULL_LOAD_ANY,
    00072     STR_ORDER_UNLOAD_NO_LOAD,
    00073   }, {
    00074     STR_ORDER_TRANSFER,
    00075     INVALID_STRING_ID,
    00076     STR_ORDER_TRANSFER_FULL_LOAD,
    00077     STR_ORDER_TRANSFER_FULL_LOAD_ANY,
    00078     STR_ORDER_TRANSFER_NO_LOAD,
    00079   }, {
    00080     /* Unload and transfer do not work together. */
    00081     INVALID_STRING_ID,
    00082     INVALID_STRING_ID,
    00083     INVALID_STRING_ID,
    00084     INVALID_STRING_ID,
    00085   }, {
    00086     STR_ORDER_NO_UNLOAD,
    00087     INVALID_STRING_ID,
    00088     STR_ORDER_NO_UNLOAD_FULL_LOAD,
    00089     STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
    00090     INVALID_STRING_ID,
    00091   }
    00092 };
    00093
    00094 static const StringID _order_non_stop_drowdown[] = {
    00095   STR_ORDER_GO_TO,
    00096   STR_ORDER_GO_NON_STOP_TO,
    00097   STR_ORDER_GO_VIA,
    00098   STR_ORDER_GO_NON_STOP_VIA,
    00099   INVALID_STRING_ID
    00100 };
    00101
    00102 static const StringID _order_full_load_drowdown[] = {
    00103   STR_ORDER_DROP_LOAD_IF_POSSIBLE,
    00104   STR_EMPTY,
    00105   STR_ORDER_DROP_FULL_LOAD_ALL,
    00106   STR_ORDER_DROP_FULL_LOAD_ANY,
    00107   STR_ORDER_DROP_NO_LOADING,
    00108   INVALID_STRING_ID
    00109 };
    00110
    00111 static const StringID _order_unload_drowdown[] = {
    00112   STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
    00113   STR_ORDER_DROP_UNLOAD,
    00114   STR_ORDER_DROP_TRANSFER,
    00115   STR_EMPTY,
    00116   STR_ORDER_DROP_NO_UNLOADING,
    00117   INVALID_STRING_ID
    00118 };
    00119
    00120 static const StringID _order_goto_dropdown[] = {
    00121   STR_ORDER_GO_TO,
    00122   STR_ORDER_GO_TO_NEAREST_DEPOT,
    00123   STR_ORDER_CONDITIONAL,
    00124   INVALID_STRING_ID
    00125 };
    00126
    00127 static const StringID _order_goto_dropdown_aircraft[] = {
    00128   STR_ORDER_GO_TO,
    00129   STR_ORDER_GO_TO_NEAREST_HANGAR,
    00130   STR_ORDER_CONDITIONAL,
    00131   INVALID_STRING_ID
    00132 };
    00133
    00134 static const StringID _order_conditional_variable[] = {
    00135   STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE,
    00136   STR_ORDER_CONDITIONAL_RELIABILITY,
    00137   STR_ORDER_CONDITIONAL_MAX_SPEED,
    00138   STR_ORDER_CONDITIONAL_AGE,
    00139   STR_ORDER_CONDITIONAL_REQUIRES_SERVICE,
    00140   STR_ORDER_CONDITIONAL_UNCONDITIONALLY,
    00141   INVALID_STRING_ID,
    00142 };
    00143
    00144 static const StringID _order_conditional_condition[] = {
    00145   STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
    00146   STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
    00147   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
    00148   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
    00149   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
    00150   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
    00151   STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
    00152   STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
    00153   INVALID_STRING_ID,
    00154 };
    00155
    00156 extern uint ConvertSpeedToDisplaySpeed(uint speed);
    00157 extern uint ConvertDisplaySpeedToSpeed(uint speed);
    00158
    00159 static const StringID _order_depot_action_dropdown[] = {
    00160   STR_ORDER_DROP_GO_ALWAYS_DEPOT,
    00161   STR_ORDER_DROP_SERVICE_DEPOT,
    00162   STR_ORDER_DROP_HALT_DEPOT,
    00163   INVALID_STRING_ID
    00164 };
    00165
    00166 static int DepotActionStringIndex(const Order *order)
    00167 {
    00168   if (order->GetDepotActionType() & ODATFB_HALT) {
    00169     return DA_STOP;
    00170   } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00171     return DA_SERVICE;
    00172   } else {
    00173     return DA_ALWAYS_GO;
    00174   }
    00175 }
    00176
    00177 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int width)
    00178 {
    00179   StringID str = (v->cur_order_index == order_index) ? STR_8805 : STR_8804;
    00180   SetDParam(6, STR_EMPTY);
    00181
    00182   switch (order->GetType()) {
    00183     case OT_DUMMY:
    00184       SetDParam(1, STR_INVALID_ORDER);
    00185       SetDParam(2, order->GetDestination());
    00186       break;
    00187
    00188     case OT_GOTO_STATION: {
    00189       OrderLoadFlags load = order->GetLoadType();
    00190       OrderUnloadFlags unload = order->GetUnloadType();
    00191
    00192       SetDParam(1, STR_GO_TO_STATION);
    00193       SetDParam(2, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0));
    00194       SetDParam(3, order->GetDestination());
    00195
    00196       if (timetable) {
    00197         SetDParam(4, STR_EMPTY);
    00198
    00199         if (order->wait_time > 0) {
    00200           SetDParam(6, STR_TIMETABLE_STAY_FOR);
    00201           SetTimetableParams(7, 8, order->wait_time);
    00202         }
    00203       } else {
    00204         SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]);
    00205       }
    00206     } break;
    00207
    00208     case OT_GOTO_DEPOT:
    00209       if (v->type == VEH_AIRCRAFT) {
    00210         if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00211           SetDParam(1, STR_GO_TO_NEAREST_DEPOT);
    00212           SetDParam(3, STR_ORDER_NEAREST_HANGAR);
    00213         } else {
    00214           SetDParam(1, STR_GO_TO_HANGAR);
    00215           SetDParam(3, order->GetDestination());
    00216         }
    00217         SetDParam(4, STR_EMPTY);
    00218       } else {
    00219         if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00220           SetDParam(1, STR_GO_TO_NEAREST_DEPOT);
    00221           SetDParam(3, STR_ORDER_NEAREST_DEPOT);
    00222         } else {
    00223           SetDParam(1, STR_GO_TO_DEPOT);
    00224           SetDParam(3, GetDepot(order->GetDestination())->town_index);
    00225         }
    00226
    00227         switch (v->type) {
    00228           case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break;
    00229           case VEH_ROAD:  SetDParam(4, STR_ORDER_ROAD_DEPOT); break;
    00230           case VEH_SHIP:  SetDParam(4, STR_ORDER_SHIP_DEPOT); break;
    00231           default: NOT_REACHED();
    00232         }
    00233       }
    00234
    00235       if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00236         SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
    00237       } else {
    00238         SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
    00239       }
    00240
    00241       if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
    00242         SetDParam(6, STR_STOP_ORDER);
    00243       }
    00244
    00245       if (!timetable && order->IsRefit()) {
    00246         SetDParam(6, (order->GetDepotActionType() & ODATFB_HALT) ? STR_REFIT_STOP_ORDER : STR_REFIT_ORDER);
    00247         SetDParam(7, GetCargo(order->GetRefitCargo())->name);
    00248       }
    00249       break;
    00250
    00251     case OT_GOTO_WAYPOINT:
    00252       SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
    00253       SetDParam(2, order->GetDestination());
    00254       break;
    00255
    00256     case OT_CONDITIONAL:
    00257       SetDParam(2, order->GetConditionSkipToOrder() + 1);
    00258       if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
    00259         SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL);
    00260       } else {
    00261         OrderConditionComparator occ = order->GetConditionComparator();
    00262         SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM);
    00263         SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
    00264         SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
    00265
    00266         uint value = order->GetConditionValue();
    00267         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00268         SetDParam(5, value);
    00269       }
    00270
    00271       if (timetable && order->wait_time > 0) {
    00272         SetDParam(6, STR_TIMETABLE_AND_TRAVEL_FOR);
    00273         SetTimetableParams(7, 8, order->wait_time);
    00274       } else {
    00275         SetDParam(6, STR_EMPTY);
    00276       }
    00277       break;
    00278
    00279     default: NOT_REACHED();
    00280   }
    00281
    00282   SetDParam(0, order_index + 1);
    00283   DrawStringTruncated(2, y, str, selected ? TC_WHITE : TC_BLACK, width);
    00284 }
    00285
    00286
    00287 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
    00288 {
    00289   Order order;
    00290   order.next  = NULL;
    00291   order.index = 0;
    00292
    00293   /* check depot first */
    00294   if (_settings_game.order.gotodepot) {
    00295     switch (GetTileType(tile)) {
    00296       case MP_RAILWAY:
    00297         if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
    00298           if (IsRailDepot(tile)) {
    00299             order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
    00300             if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00301             if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00302             return order;
    00303           }
    00304         }
    00305         break;
    00306
    00307       case MP_ROAD:
    00308         if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
    00309           order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
    00310           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00311           if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00312           return order;
    00313         }
    00314         break;
    00315
    00316       case MP_STATION:
    00317         if (v->type != VEH_AIRCRAFT) break;
    00318         if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
    00319           order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS);
    00320           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00321           return order;
    00322         }
    00323         break;
    00324
    00325       case MP_WATER:
    00326         if (v->type != VEH_SHIP) break;
    00327         if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
    00328           TileIndex tile2 = GetOtherShipDepotTile(tile);
    00329
    00330           order.MakeGoToDepot(GetDepotByTile(tile < tile2 ? tile : tile2)->index, ODTFB_PART_OF_ORDERS);
    00331           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00332           return order;
    00333         }
    00334
    00335       default:
    00336         break;
    00337     }
    00338   }
    00339
    00340   /* check waypoint */
    00341   if (IsRailWaypointTile(tile) &&
    00342       v->type == VEH_TRAIN &&
    00343       IsTileOwner(tile, _local_company)) {
    00344     order.MakeGoToWaypoint(GetWaypointByTile(tile)->index);
    00345     if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
    00346     return order;
    00347   }
    00348
    00349   if (IsTileType(tile, MP_STATION)) {
    00350     StationID st_index = GetStationIndex(tile);
    00351     const Station *st = GetStation(st_index);
    00352
    00353     if (st->owner == _local_company || st->owner == OWNER_NONE) {
    00354       byte facil;
    00355       (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
    00356       (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
    00357       (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
    00358       (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) ||
    00359       (facil = FACIL_TRUCK_STOP, 1);
    00360       if (st->facilities & facil) {
    00361         order.MakeGoToStation(st_index);
    00362         if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
    00363         if (_settings_client.gui.new_nonstop && (v->type == VEH_TRAIN || v->type == VEH_ROAD)) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00364         return order;
    00365       }
    00366     }
    00367   }
    00368
    00369   /* not found */
    00370   order.Free();
    00371   return order;
    00372 }
    00373
    00374 struct OrdersWindow : public Window {
    00375 private:
    00377   enum OrderPlaceObjectState {
    00378     OPOS_GOTO,
    00379     OPOS_CONDITIONAL,
    00380   };
    00381
    00382   int selected_order;
    00383   OrderPlaceObjectState goto_type;
    00384   const Vehicle *vehicle;
    00385
    00391   int OrderGetSel()
    00392   {
    00393     int num = this->selected_order;
    00394     return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
    00395   }
    00396
    00407   int GetOrderFromPt(int y)
    00408   {
    00409     /*
    00410      * Calculation description:
    00411      * 15 = 14 (w->widget[ORDER_WIDGET_ORDER_LIST].top) + 1 (frame-line)
    00412      * 10 = order text hight
    00413      */
    00414     int sel = (y - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / 10;
    00415
    00416     if ((uint)sel >= this->vscroll.cap) return INVALID_ORDER;
    00417
    00418     sel += this->vscroll.pos;
    00419
    00420     return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_ORDER;
    00421   }
    00422
    00423   bool HandleOrderVehClick(const Vehicle *u)
    00424   {
    00425     if (u->type != this->vehicle->type) return false;
    00426
    00427     if (!u->IsPrimaryVehicle()) {
    00428       u = u->First();
    00429       if (!u->IsPrimaryVehicle()) return false;
    00430     }
    00431
    00432     /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
    00433      * obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */
    00434     if (this->vehicle->GetNumOrders() != 0 && _ctrl_pressed == 0) return false;
    00435
    00436     if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY,
    00437       _ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
    00438       this->selected_order = -1;
    00439       ResetObjectToPlace();
    00440     }
    00441
    00442     return true;
    00443   }
    00444
    00450   static void OrderClick_Goto(OrdersWindow *w, int i)
    00451   {
    00452     w->InvalidateWidget(ORDER_WIDGET_GOTO);
    00453     w->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO);
    00454     if (w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    00455       _place_clicked_vehicle = NULL;
    00456       SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, VHM_RECT, w);
    00457       w->goto_type = OPOS_GOTO;
    00458     } else {
    00459       ResetObjectToPlace();
    00460     }
    00461   }
    00462
    00469   static void OrderClick_FullLoad(OrdersWindow *w, int load_type)
    00470   {
    00471     VehicleOrderID sel_ord = w->OrderGetSel();
    00472     const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00473
    00474     if (order == NULL || order->GetLoadType() == load_type) return;
    00475
    00476     if (load_type < 0) {
    00477       load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
    00478     }
    00479     DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    00480   }
    00481
    00487   static void OrderClick_Service(OrdersWindow *w, int i)
    00488   {
    00489     VehicleOrderID sel_ord = w->OrderGetSel();
    00490
    00491     if (i < 0) {
    00492       const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00493       if (order == NULL) return;
    00494       i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
    00495     }
    00496     DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    00497   }
    00498
    00504   static void OrderClick_NearestDepot(OrdersWindow *w, int i)
    00505   {
    00506     Order order;
    00507     order.next = NULL;
    00508     order.index = 0;
    00509     order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS);
    00510     order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
    00511
    00512     DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
    00513   }
    00514
    00520   static void OrderClick_Conditional(OrdersWindow *w, int i)
    00521   {
    00522     w->InvalidateWidget(ORDER_WIDGET_GOTO);
    00523     w->LowerWidget(ORDER_WIDGET_GOTO);
    00524     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, VHM_RECT, w);
    00525     w->goto_type = OPOS_CONDITIONAL;
    00526   }
    00527
    00533   static void OrderClick_Unload(OrdersWindow *w, int unload_type)
    00534   {
    00535     VehicleOrderID sel_ord = w->OrderGetSel();
    00536     const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00537
    00538     if (order == NULL || order->GetUnloadType() == unload_type) return;
    00539
    00540     if (unload_type < 0) {
    00541       unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
    00542     }
    00543
    00544     DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    00545   }
    00546
    00553   static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
    00554   {
    00555     VehicleOrderID sel_ord = w->OrderGetSel();
    00556     const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00557
    00558     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00559
    00560     /* Keypress if negative, so 'toggle' to the next */
    00561     if (non_stop < 0) {
    00562       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00563     }
    00564
    00565     w->InvalidateWidget(ORDER_WIDGET_NON_STOP);
    00566     DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    00567   }
    00568
    00576   static void OrderClick_Skip(OrdersWindow *w, int i)
    00577   {
    00578     /* Don't skip when there's nothing to skip */
    00579     if (_ctrl_pressed && w->vehicle->cur_order_index == w->OrderGetSel()) return;
    00580     if (w->vehicle->GetNumOrders() <= 1) return;
    00581
    00582     DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->GetNumOrders()),
    00583         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER));
    00584   }
    00585
    00591   static void OrderClick_Delete(OrdersWindow *w, int i)
    00592   {
    00593     /* When networking, move one order lower */
    00594     int selected = w->selected_order + (int)_networking;
    00595
    00596     if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER))) {
    00597       w->selected_order = selected >= w->vehicle->GetNumOrders() ? -1 : selected;
    00598     }
    00599   }
    00600
    00608   static void OrderClick_Refit(OrdersWindow *w, int i)
    00609   {
    00610     if (_ctrl_pressed) {
    00611       /* Cancel refitting */
    00612       DoCommandP(w->vehicle->tile, w->vehicle->index, (w->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00613     } else {
    00614       ShowVehicleRefitWindow(w->vehicle, w->OrderGetSel(), w);
    00615     }
    00616   }
    00617   typedef void Handler(OrdersWindow*, int);
    00618   struct KeyToEvent {
    00619     uint16 keycode;
    00620     Handler *proc;
    00621   };
    00622
    00623 public:
    00624   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window(desc, v->index)
    00625   {
    00626     this->owner = v->owner;
    00627     this->vscroll.cap = 6;
    00628     this->resize.step_height = 10;
    00629     this->selected_order = -1;
    00630     this->vehicle = v;
    00631
    00632     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00633       /* If there are less than 2 station, make Go To active. */
    00634       int station_orders = 0;
    00635       const Order *order;
    00636       FOR_VEHICLE_ORDERS(v, order) {
    00637         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00638       }
    00639
    00640       if (station_orders < 2) OrderClick_Goto(this, 0);
    00641     }
    00642
    00643     if (_settings_game.order.timetabling) {
    00644       this->widget[ORDER_WIDGET_CAPTION].right -= 61;
    00645     } else {
    00646       this->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
    00647     }
    00648     this->FindWindowPlacementAndResize(desc);
    00649   }
    00650
    00651   virtual void OnInvalidateData(int data)
    00652   {
    00653     switch (data) {
    00654       case 0:
    00655         /* Autoreplace replaced the vehicle */
    00656         this->vehicle = GetVehicle(this->window_number);
    00657         break;
    00658
    00659       case -1:
    00660         /* Removed / replaced all orders (after deleting / sharing) */
    00661         if (this->selected_order == -1) break;
    00662
    00663         this->DeleteChildWindows();
    00664         HideDropDownMenu(this);
    00665         this->selected_order = -1;
    00666         break;
    00667
    00668       default: {
    00669         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00670          * the order is being created / removed */
    00671         if (this->selected_order == -1) break;
    00672
    00673         VehicleOrderID from = GB(data, 0, 8);
    00674         VehicleOrderID to   = GB(data, 8, 8);
    00675
    00676         if (from == to) break; // no need to change anything
    00677
    00678         if (from != this->selected_order) {
    00679           /* Moving from preceeding order? */
    00680           this->selected_order -= (int)(from <= this->selected_order);
    00681           /* Moving to   preceeding order? */
    00682           this->selected_order += (int)(to   <= this->selected_order);
    00683           break;
    00684         }
    00685
    00686         /* Now we are modifying the selected order */
    00687         if (to == INVALID_VEH_ORDER_ID) {
    00688           /* Deleting selected order */
    00689           this->DeleteChildWindows();
    00690           HideDropDownMenu(this);
    00691           this->selected_order = -1;
    00692           break;
    00693         }
    00694
    00695         /* Moving selected order */
    00696         this->selected_order = to;
    00697       } break;
    00698     }
    00699   }
    00700
    00701   virtual void OnPaint()
    00702   {
    00703     bool shared_orders = this->vehicle->IsOrderListShared();
    00704
    00705     SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
    00706
    00707     int sel = OrderGetSel();
    00708     const Order *order = GetVehicleOrder(this->vehicle, sel);
    00709
    00710     if (this->vehicle->owner == _local_company) {
    00711       /* Set the strings for the dropdown boxes. */
    00712       this->widget[ORDER_WIDGET_COND_VARIABLE].data   = _order_conditional_variable[order == NULL ? 0 : order->GetConditionVariable()];
    00713       this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    00714
    00715       /* skip */
    00716       this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1);
    00717
    00718       /* delete */
    00719       this->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
    00720           (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00721
    00722       /* non-stop only for trains */
    00723       this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP,  (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) || order == NULL);
    00724       this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_NON_STOP));
    00725       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    00726       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_FULL_LOAD));
    00727       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    00728       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_UNLOAD));
    00729       /* Disable list of vehicles with the same shared orders if there is no list */
    00730       this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
    00731       this->SetWidgetDisabledState(ORDER_WIDGET_REFIT,     order == NULL); // Refit
    00732       this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE,   order == NULL); // Service
    00733       this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE_DROPDOWN,   order == NULL); // Service
    00734       this->HideWidget(ORDER_WIDGET_REFIT); // Refit
    00735       this->HideWidget(ORDER_WIDGET_SERVICE); // Service
    00736       this->HideWidget(ORDER_WIDGET_SERVICE_DROPDOWN); // Service
    00737
    00738       this->HideWidget(ORDER_WIDGET_COND_VARIABLE);
    00739       this->HideWidget(ORDER_WIDGET_COND_COMPARATOR);
    00740       this->HideWidget(ORDER_WIDGET_COND_VALUE);
    00741     }
    00742
    00743     this->ShowWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00744     this->ShowWidget(ORDER_WIDGET_NON_STOP);
    00745     this->ShowWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00746     this->ShowWidget(ORDER_WIDGET_UNLOAD);
    00747     this->ShowWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00748     this->ShowWidget(ORDER_WIDGET_FULL_LOAD);
    00749
    00750     this->RaiseWidget(ORDER_WIDGET_NON_STOP);
    00751     this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
    00752     this->RaiseWidget(ORDER_WIDGET_UNLOAD);
    00753     this->RaiseWidget(ORDER_WIDGET_SERVICE);
    00754
    00755     if (order != NULL) {
    00756       this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00757       switch (order->GetType()) {
    00758         case OT_GOTO_STATION:
    00759           if (!GetStation(order->GetDestination())->IsBuoy()) {
    00760             this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    00761             this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    00762             break;
    00763           }
    00764           /* Fall-through */
    00765
    00766         case OT_GOTO_WAYPOINT:
    00767           this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00768           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00769           this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00770           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00771           break;
    00772
    00773         case OT_GOTO_DEPOT:
    00774           /* Remove unload and replace it with refit */
    00775           this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00776           this->HideWidget(ORDER_WIDGET_UNLOAD);
    00777           this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00778           this->HideWidget(ORDER_WIDGET_FULL_LOAD);
    00779           this->ShowWidget(ORDER_WIDGET_REFIT);
    00780           this->ShowWidget(ORDER_WIDGET_SERVICE_DROPDOWN);
    00781           this->ShowWidget(ORDER_WIDGET_SERVICE);
    00782           this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    00783           break;
    00784
    00785         case OT_CONDITIONAL: {
    00786           this->HideWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00787           this->HideWidget(ORDER_WIDGET_NON_STOP);
    00788           this->HideWidget(ORDER_WIDGET_UNLOAD);
    00789           this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00790           this->HideWidget(ORDER_WIDGET_FULL_LOAD);
    00791           this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00792           this->ShowWidget(ORDER_WIDGET_COND_VARIABLE);
    00793           this->ShowWidget(ORDER_WIDGET_COND_COMPARATOR);
    00794           this->ShowWidget(ORDER_WIDGET_COND_VALUE);
    00795
    00796           OrderConditionVariable ocv = order->GetConditionVariable();
    00797           this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    00798           this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    00799
    00800           uint value = order->GetConditionValue();
    00801           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00802           SetDParam(1, value);
    00803         } break;
    00804
    00805         default: // every other orders
    00806           this->DisableWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00807           this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00808           this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00809           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00810           this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00811           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00812       }
    00813     }
    00814
    00815     SetDParam(0, this->vehicle->index);
    00816     this->DrawWidgets();
    00817
    00818     int y = 15;
    00819
    00820     int i = this->vscroll.pos;
    00821     order = GetVehicleOrder(this->vehicle, i);
    00822     StringID str;
    00823     while (order != NULL) {
    00824       /* Don't draw anything if it extends past the end of the window. */
    00825       if (i - this->vscroll.pos >= this->vscroll.cap) break;
    00826
    00827       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, this->widget[ORDER_WIDGET_ORDER_LIST].right - 4);
    00828       y += 10;
    00829
    00830       i++;
    00831       order = order->next;
    00832     }
    00833
    00834     if (i - this->vscroll.pos < this->vscroll.cap) {
    00835       str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
    00836       DrawString(2, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
    00837     }
    00838   }
    00839
    00840   virtual void OnClick(Point pt, int widget)
    00841   {
    00842     switch (widget) {
    00843       case ORDER_WIDGET_ORDER_LIST: {
    00844         ResetObjectToPlace();
    00845
    00846         int sel = this->GetOrderFromPt(pt.y);
    00847
    00848         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    00849           const Order *ord = GetVehicleOrder(this->vehicle, sel);
    00850           TileIndex xy = INVALID_TILE;
    00851
    00852           switch (ord->GetType()) {
    00853             case OT_GOTO_STATION:  xy = GetStation(ord->GetDestination())->xy ; break;
    00854             case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->GetDestination())->xy; break;
    00855             case OT_GOTO_DEPOT:
    00856               if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
    00857               xy = (this->vehicle->type == VEH_AIRCRAFT) ?  GetStation(ord->GetDestination())->xy : GetDepot(ord->GetDestination())->xy;
    00858               break;
    00859             default:
    00860               break;
    00861           }
    00862
    00863           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    00864           return;
    00865         }
    00866
    00867         /* This order won't be selected any more, close all child windows and dropdowns */
    00868         this->DeleteChildWindows();
    00869         HideDropDownMenu(this);
    00870
    00871         if (sel == INVALID_ORDER || sel == this->selected_order) {
    00872           /* Deselect clicked order */
    00873           this->selected_order = -1;
    00874         } else {
    00875           /* Select clicked order */
    00876           this->selected_order = sel;
    00877
    00878           if (this->vehicle->owner == _local_company) {
    00879             /* Activate drag and drop */
    00880             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, VHM_DRAG, this);
    00881           }
    00882         }
    00883
    00884         this->SetDirty();
    00885       } break;
    00886
    00887       case ORDER_WIDGET_SKIP:
    00888         OrderClick_Skip(this, 0);
    00889         break;
    00890
    00891       case ORDER_WIDGET_DELETE:
    00892         OrderClick_Delete(this, 0);
    00893         break;
    00894
    00895       case ORDER_WIDGET_NON_STOP:
    00896         OrderClick_Nonstop(this, -1);
    00897         break;
    00898
    00899       case ORDER_WIDGET_NON_STOP_DROPDOWN: {
    00900         const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00901         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));
    00902       } break;
    00903
    00904       case ORDER_WIDGET_GOTO:
    00905         OrderClick_Goto(this, 0);
    00906         break;
    00907
    00908       case ORDER_WIDGET_GOTO_DROPDOWN:
    00909         ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO_DROPDOWN, 0, 0);
    00910         break;
    00911
    00912       case ORDER_WIDGET_FULL_LOAD:
    00913         OrderClick_FullLoad(this, -1);
    00914         break;
    00915
    00916       case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
    00917         ShowDropDownMenu(this, _order_full_load_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
    00918         break;
    00919
    00920       case ORDER_WIDGET_UNLOAD:
    00921         OrderClick_Unload(this, -1);
    00922         break;
    00923
    00924       case ORDER_WIDGET_UNLOAD_DROPDOWN:
    00925         ShowDropDownMenu(this, _order_unload_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
    00926         break;
    00927
    00928       case ORDER_WIDGET_REFIT:
    00929         OrderClick_Refit(this, 0);
    00930         break;
    00931
    00932       case ORDER_WIDGET_SERVICE:
    00933         OrderClick_Service(this, -1);
    00934         break;
    00935
    00936       case ORDER_WIDGET_SERVICE_DROPDOWN:
    00937         ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
    00938         break;
    00939
    00940       case ORDER_WIDGET_TIMETABLE_VIEW:
    00941         ShowTimetableWindow(this->vehicle);
    00942         break;
    00943
    00944       case ORDER_WIDGET_COND_VARIABLE:
    00945         ShowDropDownMenu(this, _order_conditional_variable, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
    00946         break;
    00947
    00948       case ORDER_WIDGET_COND_COMPARATOR: {
    00949         const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00950         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    00951       } break;
    00952
    00953       case ORDER_WIDGET_COND_VALUE: {
    00954         const Order *order = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00955         uint value = order->GetConditionValue();
    00956         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00957         SetDParam(0, value);
    00958         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
    00959       } break;
    00960
    00961       case ORDER_WIDGET_SHARED_ORDER_LIST:
    00962         ShowVehicleListWindow(this->vehicle);
    00963         break;
    00964     }
    00965   }
    00966
    00967   virtual void OnQueryTextFinished(char *str)
    00968   {
    00969     if (!StrEmpty(str)) {
    00970       VehicleOrderID sel = this->OrderGetSel();
    00971       uint value = atoi(str);
    00972
    00973       switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) {
    00974         case OCV_MAX_SPEED:
    00975           value = ConvertDisplaySpeedToSpeed(value);
    00976           break;
    00977
    00978         case OCV_RELIABILITY:
    00979         case OCV_LOAD_PERCENTAGE:
    00980           value = Clamp(value, 0, 100);
    00981
    00982         default:
    00983           break;
    00984       }
    00985       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    00986     }
    00987   }
    00988
    00989   virtual void OnDropdownSelect(int widget, int index)
    00990   {
    00991     switch (widget) {
    00992       case ORDER_WIDGET_NON_STOP_DROPDOWN:
    00993         OrderClick_Nonstop(this, index);
    00994         break;
    00995
    00996       case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
    00997         OrderClick_FullLoad(this, index);
    00998         break;
    00999
    01000       case ORDER_WIDGET_UNLOAD_DROPDOWN:
    01001         OrderClick_Unload(this, index);
    01002         break;
    01003
    01004       case ORDER_WIDGET_GOTO_DROPDOWN:
    01005         switch (index) {
    01006           case 0: OrderClick_Goto(this, 0); break;
    01007           case 1: OrderClick_NearestDepot(this, 0); break;
    01008           case 2: OrderClick_Conditional(this, 0); break;
    01009           default: NOT_REACHED();
    01010         }
    01011         break;
    01012
    01013       case ORDER_WIDGET_SERVICE_DROPDOWN:
    01014         OrderClick_Service(this, index);
    01015         break;
    01016
    01017       case ORDER_WIDGET_COND_VARIABLE:
    01018         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    01019         break;
    01020
    01021       case ORDER_WIDGET_COND_COMPARATOR:
    01022         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_COMPARATOR | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
    01023         break;
    01024     }
    01025   }
    01026
    01027   virtual void OnDragDrop(Point pt, int widget)
    01028   {
    01029     switch (widget) {
    01030       case ORDER_WIDGET_ORDER_LIST: {
    01031         int from_order = this->OrderGetSel();
    01032         int to_order = this->GetOrderFromPt(pt.y);
    01033
    01034         if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
    01035             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) {
    01036           this->selected_order = -1;
    01037         }
    01038       } break;
    01039
    01040       case ORDER_WIDGET_DELETE:
    01041         OrderClick_Delete(this, 0);
    01042         break;
    01043     }
    01044
    01045     ResetObjectToPlace();
    01046   }
    01047
    01048   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01049   {
    01050     static const KeyToEvent keytoevent[] = {
    01051       {'D', OrderClick_Skip},
    01052       {'F', OrderClick_Delete},
    01053       {'G', OrderClick_Goto},
    01054       {'H', OrderClick_Nonstop},
    01055       {'J', OrderClick_FullLoad},
    01056       {'K', OrderClick_Unload},
    01057       //('?', OrderClick_Service},
    01058     };
    01059
    01060     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01061
    01062     for (uint i = 0; i < lengthof(keytoevent); i++) {
    01063       if (keycode == keytoevent[i].keycode) {
    01064         keytoevent[i].proc(this, -1);
    01065         return ES_HANDLED;
    01066       }
    01067     }
    01068     return ES_NOT_HANDLED;
    01069   }
    01070
    01071   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01072   {
    01073     if (this->goto_type == OPOS_GOTO) {
    01074       /* check if we're clicking on a vehicle first.. clone orders in that case. */
    01075       const Vehicle *v = CheckMouseOverVehicle();
    01076       if (v != NULL && this->HandleOrderVehClick(v)) return;
    01077
    01078       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01079       if (!cmd.IsValid()) return;
    01080
    01081       if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
    01082         /* With quick goto the Go To button stays active */
    01083         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01084       }
    01085     }
    01086   }
    01087
    01088   virtual void OnPlaceObjectAbort()
    01089   {
    01090     if (this->goto_type == OPOS_CONDITIONAL) {
    01091       this->goto_type = OPOS_GOTO;
    01092       if (_cursor.pos.x >= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].left) &&
    01093           _cursor.pos.y >= (this->top  + this->widget[ORDER_WIDGET_ORDER_LIST].top) &&
    01094           _cursor.pos.x <= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].right) &&
    01095           _cursor.pos.y <= (this->top  + this->widget[ORDER_WIDGET_ORDER_LIST].bottom)) {
    01096         int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01097         if (order_id != INVALID_ORDER) {
    01098           Order order;
    01099           order.next = NULL;
    01100           order.index = 0;
    01101           order.MakeConditional(order_id);
    01102
    01103           DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
    01104         }
    01105       }
    01106     }
    01107     this->RaiseWidget(ORDER_WIDGET_GOTO);
    01108     this->InvalidateWidget(ORDER_WIDGET_GOTO);
    01109   }
    01110
    01111   virtual void OnMouseLoop()
    01112   {
    01113     const Vehicle *v = _place_clicked_vehicle;
    01114     /*
    01115      * Check if we clicked on a vehicle
    01116      * and if the GOTO button of this window is pressed
    01117      * This is because of all open order windows WE_MOUSELOOP is called
    01118      * and if you have 3 windows open, and this check is not done
    01119      * the order is copied to the last open window instead of the
    01120      * one where GOTO is enabled
    01121      */
    01122     if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    01123       _place_clicked_vehicle = NULL;
    01124       this->HandleOrderVehClick(v);
    01125     }
    01126   }
    01127
    01128   virtual void OnResize(Point new_size, Point delta)
    01129   {
    01130     /* Update the scroll + matrix */
    01131     this->vscroll.cap = (this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
    01132   }
    01133
    01134   virtual void OnTimeout()
    01135   {
    01136     /* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
    01137     for (uint i = 0; i < this->widget_count; i++) {
    01138       if (this->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
    01139         this->RaiseWidget(i);
    01140         this->InvalidateWidget(i);
    01141       }
    01142     }
    01143   }
    01144 };
    01145
    01149 static const Widget _orders_train_widgets[] = {
    01150   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01151   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,         STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01152   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW,      STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01153   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,                STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01154
    01155   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                     STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01156
    01157   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01158
    01159   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    88,    99, STR_8823_SKIP,           STR_8853_SKIP_THE_CURRENT_ORDER},     // ORDER_WIDGET_SKIP
    01160   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    88,    99, STR_8824_DELETE,         STR_8854_DELETE_THE_HIGHLIGHTED},     // ORDER_WIDGET_DELETE
    01161   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_NON_STOP},          // ORDER_WIDGET_NON_STOP_DROPDOWN
    01162   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   111,    76,    87, STR_ORDER_NON_STOP,      STR_ORDER_TOOLTIP_NON_STOP},          // ORDER_WIDGET_NON_STOP
    01163   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    88,    99, STR_EMPTY,               STR_ORDER_GO_TO_DROPDOWN_TOOLTIP},    // ORDER_WIDGET_GOTO_DROPDOWN
    01164   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    88,    99, STR_8826_GO_TO,          STR_8856_INSERT_A_NEW_ORDER_BEFORE},  // ORDER_WIDGET_GOTO
    01165   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_FULL_LOAD},         // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01166   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   235,    76,    87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD},      // ORDER_WIDGET_FULL_LOAD
    01167   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01168   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
    01169   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
    01170   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
    01171   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
    01172
    01173   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
    01174   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
    01175   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_CONDITIONAL_VALUE,   STR_ORDER_CONDITIONAL_VALUE_TOOLTIP},      // ORDER_WIDGET_COND_VALUE
    01176
    01177   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,   372,   373,    76,    99, 0x0,                     STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01178   { WWT_PUSHIMGBTN,   RESIZE_LRTB,   COLOUR_GREY,   372,   385,    76,    87, SPR_SHARED_ORDERS_ICON,  STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
    01179
    01180   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    88,    99, 0x0,                     STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01181   {   WIDGETS_END},
    01182 };
    01183
    01184 static const WindowDesc _orders_train_desc(
    01185   WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
    01186   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01187   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    01188   _orders_train_widgets
    01189 );
    01190
    01194 static const Widget _orders_widgets[] = {
    01195   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01196   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,         STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01197   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW,      STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01198   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,                STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01199
    01200   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                     STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01201
    01202   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01203
    01204   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    88,    99, STR_8823_SKIP,           STR_8853_SKIP_THE_CURRENT_ORDER},     // ORDER_WIDGET_SKIP
    01205   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    88,    99, STR_8824_DELETE,         STR_8854_DELETE_THE_HIGHLIGHTED},     // ORDER_WIDGET_DELETE
    01206   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                     0x0},                                 // ORDER_WIDGET_NON_STOP_DROPDOWN
    01207   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                     0x0},                                 // ORDER_WIDGET_NON_STOP
    01208   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    88,    99, STR_EMPTY,               STR_ORDER_GO_TO_DROPDOWN_TOOLTIP},    // ORDER_WIDGET_GOTO_DROPDOWN
    01209   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    88,    99, STR_8826_GO_TO,          STR_8856_INSERT_A_NEW_ORDER_BEFORE},  // ORDER_WIDGET_GOTO
    01210   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   185,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_FULL_LOAD},         // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01211   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   173,    76,    87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD},      // ORDER_WIDGET_FULL_LOAD
    01212   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01213   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
    01214   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   185,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
    01215   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
    01216   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
    01217
    01218   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
    01219   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
    01220   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_CONDITIONAL_VALUE,   STR_ORDER_CONDITIONAL_VALUE_TOOLTIP},      // ORDER_WIDGET_COND_VALUE
    01221
    01222   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,   372,   373,    76,    99, 0x0,                     STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01223   { WWT_PUSHIMGBTN,   RESIZE_LRTB,   COLOUR_GREY,   372,   385,    76,    87, SPR_SHARED_ORDERS_ICON,  STR_VEH_WITH_SHARED_ORDERS_LIST_TIP}, // ORDER_WIDGET_SHARED_ORDER_LIST
    01224
    01225   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    88,    99, 0x0,                     STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01226   {   WIDGETS_END},
    01227 };
    01228
    01229 static const WindowDesc _orders_desc(
    01230   WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
    01231   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01232   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    01233   _orders_widgets
    01234 );
    01235
    01239 static const Widget _other_orders_widgets[] = {
    01240   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,           STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01241   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,    STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01242   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01243   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,           STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01244
    01245   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01246
    01247   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01248
    01249   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SKIP
    01250   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_DELETE
    01251   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_NON_STOP_DROPDOWN
    01252   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_NON_STOP
    01253   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_GOTO_DROPDOWN
    01254   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_GOTO
    01255   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01256   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_FULL_LOAD
    01257   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01258   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD
    01259   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_REFIT
    01260   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE_DROPDOWN
    01261   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE
    01262
    01263   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_VARIABLE
    01264   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_COMPARATOR
    01265   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_VALUE
    01266
    01267   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,     0,   373,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01268   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SHARED_ORDER_LIST
    01269
    01270   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    76,    87, 0x0,                STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01271   {   WIDGETS_END},
    01272 };
    01273
    01274 static const WindowDesc _other_orders_desc(
    01275   WDP_AUTO, WDP_AUTO, 386, 88, 386, 88,
    01276   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01277   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE | WDF_CONSTRUCTION,
    01278   _other_orders_widgets
    01279 );
    01280
    01281 void ShowOrdersWindow(const Vehicle *v)
    01282 {
    01283   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01284   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01285   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01286
    01287   if (v->owner != _local_company) {
    01288     new OrdersWindow(&_other_orders_desc, v);
    01289   } else {
    01290     new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
    01291   }
    01292 }