# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 16248 2009-05-06 23:21:43Z 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                 _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00301             if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    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               _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00311           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    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, ONSF_STOP_EVERYWHERE);
    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, ONSF_STOP_EVERYWHERE);
    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         _settings_client.gui.new_nonstop && (w->vehicle->type == VEH_TRAIN || w->vehicle->type == VEH_ROAD) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00511     order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
    00512
    00513     DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
    00514   }
    00515
    00521   static void OrderClick_Conditional(OrdersWindow *w, int i)
    00522   {
    00523     w->InvalidateWidget(ORDER_WIDGET_GOTO);
    00524     w->LowerWidget(ORDER_WIDGET_GOTO);
    00525     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, VHM_RECT, w);
    00526     w->goto_type = OPOS_CONDITIONAL;
    00527   }
    00528
    00534   static void OrderClick_Unload(OrdersWindow *w, int unload_type)
    00535   {
    00536     VehicleOrderID sel_ord = w->OrderGetSel();
    00537     const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00538
    00539     if (order == NULL || order->GetUnloadType() == unload_type) return;
    00540
    00541     if (unload_type < 0) {
    00542       unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
    00543     }
    00544
    00545     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));
    00546   }
    00547
    00554   static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
    00555   {
    00556     VehicleOrderID sel_ord = w->OrderGetSel();
    00557     const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
    00558
    00559     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00560
    00561     /* Keypress if negative, so 'toggle' to the next */
    00562     if (non_stop < 0) {
    00563       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00564     }
    00565
    00566     w->InvalidateWidget(ORDER_WIDGET_NON_STOP);
    00567     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));
    00568   }
    00569
    00577   static void OrderClick_Skip(OrdersWindow *w, int i)
    00578   {
    00579     /* Don't skip when there's nothing to skip */
    00580     if (_ctrl_pressed && w->vehicle->cur_order_index == w->OrderGetSel()) return;
    00581     if (w->vehicle->GetNumOrders() <= 1) return;
    00582
    00583     DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->GetNumOrders()),
    00584         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER));
    00585   }
    00586
    00592   static void OrderClick_Delete(OrdersWindow *w, int i)
    00593   {
    00594     /* When networking, move one order lower */
    00595     int selected = w->selected_order + (int)_networking;
    00596
    00597     if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER))) {
    00598       w->selected_order = selected >= w->vehicle->GetNumOrders() ? -1 : selected;
    00599     }
    00600   }
    00601
    00609   static void OrderClick_Refit(OrdersWindow *w, int i)
    00610   {
    00611     if (_ctrl_pressed) {
    00612       /* Cancel refitting */
    00613       DoCommandP(w->vehicle->tile, w->vehicle->index, (w->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00614     } else {
    00615       ShowVehicleRefitWindow(w->vehicle, w->OrderGetSel(), w);
    00616     }
    00617   }
    00618   typedef void Handler(OrdersWindow*, int);
    00619   struct KeyToEvent {
    00620     uint16 keycode;
    00621     Handler *proc;
    00622   };
    00623
    00624 public:
    00625   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window(desc, v->index)
    00626   {
    00627     this->owner = v->owner;
    00628     this->vscroll.cap = 6;
    00629     this->resize.step_height = 10;
    00630     this->selected_order = -1;
    00631     this->vehicle = v;
    00632
    00633     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00634       /* If there are less than 2 station, make Go To active. */
    00635       int station_orders = 0;
    00636       const Order *order;
    00637       FOR_VEHICLE_ORDERS(v, order) {
    00638         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00639       }
    00640
    00641       if (station_orders < 2) OrderClick_Goto(this, 0);
    00642     }
    00643
    00644     if (_settings_game.order.timetabling) {
    00645       this->widget[ORDER_WIDGET_CAPTION].right -= 61;
    00646     } else {
    00647       this->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
    00648     }
    00649     this->FindWindowPlacementAndResize(desc);
    00650   }
    00651
    00652   virtual void OnInvalidateData(int data)
    00653   {
    00654     switch (data) {
    00655       case 0:
    00656         /* Autoreplace replaced the vehicle */
    00657         this->vehicle = GetVehicle(this->window_number);
    00658         break;
    00659
    00660       case -1:
    00661         /* Removed / replaced all orders (after deleting / sharing) */
    00662         if (this->selected_order == -1) break;
    00663
    00664         this->DeleteChildWindows();
    00665         HideDropDownMenu(this);
    00666         this->selected_order = -1;
    00667         break;
    00668
    00669       default: {
    00670         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00671          * the order is being created / removed */
    00672         if (this->selected_order == -1) break;
    00673
    00674         VehicleOrderID from = GB(data, 0, 8);
    00675         VehicleOrderID to   = GB(data, 8, 8);
    00676
    00677         if (from == to) break; // no need to change anything
    00678
    00679         if (from != this->selected_order) {
    00680           /* Moving from preceeding order? */
    00681           this->selected_order -= (int)(from <= this->selected_order);
    00682           /* Moving to   preceeding order? */
    00683           this->selected_order += (int)(to   <= this->selected_order);
    00684           break;
    00685         }
    00686
    00687         /* Now we are modifying the selected order */
    00688         if (to == INVALID_VEH_ORDER_ID) {
    00689           /* Deleting selected order */
    00690           this->DeleteChildWindows();
    00691           HideDropDownMenu(this);
    00692           this->selected_order = -1;
    00693           break;
    00694         }
    00695
    00696         /* Moving selected order */
    00697         this->selected_order = to;
    00698       } break;
    00699     }
    00700   }
    00701
    00702   virtual void OnPaint()
    00703   {
    00704     bool shared_orders = this->vehicle->IsOrderListShared();
    00705
    00706     SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
    00707
    00708     int sel = OrderGetSel();
    00709     const Order *order = GetVehicleOrder(this->vehicle, sel);
    00710
    00711     if (this->vehicle->owner == _local_company) {
    00712       /* Set the strings for the dropdown boxes. */
    00713       this->widget[ORDER_WIDGET_COND_VARIABLE].data   = _order_conditional_variable[order == NULL ? 0 : order->GetConditionVariable()];
    00714       this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    00715
    00716       /* skip */
    00717       this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1);
    00718
    00719       /* delete */
    00720       this->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
    00721           (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00722
    00723       /* non-stop only for trains */
    00724       this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP,  (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) || order == NULL);
    00725       this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_NON_STOP));
    00726       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    00727       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_FULL_LOAD));
    00728       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    00729       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD_DROPDOWN, this->IsWidgetDisabled(ORDER_WIDGET_UNLOAD));
    00730       /* Disable list of vehicles with the same shared orders if there is no list */
    00731       this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
    00732       this->SetWidgetDisabledState(ORDER_WIDGET_REFIT,     order == NULL); // Refit
    00733       this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE,   order == NULL); // Service
    00734       this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE_DROPDOWN,   order == NULL); // Service
    00735       this->HideWidget(ORDER_WIDGET_REFIT); // Refit
    00736       this->HideWidget(ORDER_WIDGET_SERVICE); // Service
    00737       this->HideWidget(ORDER_WIDGET_SERVICE_DROPDOWN); // Service
    00738
    00739       this->HideWidget(ORDER_WIDGET_COND_VARIABLE);
    00740       this->HideWidget(ORDER_WIDGET_COND_COMPARATOR);
    00741       this->HideWidget(ORDER_WIDGET_COND_VALUE);
    00742     }
    00743
    00744     this->ShowWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00745     this->ShowWidget(ORDER_WIDGET_NON_STOP);
    00746     this->ShowWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00747     this->ShowWidget(ORDER_WIDGET_UNLOAD);
    00748     this->ShowWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00749     this->ShowWidget(ORDER_WIDGET_FULL_LOAD);
    00750
    00751     this->RaiseWidget(ORDER_WIDGET_NON_STOP);
    00752     this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
    00753     this->RaiseWidget(ORDER_WIDGET_UNLOAD);
    00754     this->RaiseWidget(ORDER_WIDGET_SERVICE);
    00755
    00756     if (order != NULL) {
    00757       this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00758       switch (order->GetType()) {
    00759         case OT_GOTO_STATION:
    00760           if (!GetStation(order->GetDestination())->IsBuoy()) {
    00761             this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    00762             this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    00763             break;
    00764           }
    00765           /* Fall-through */
    00766
    00767         case OT_GOTO_WAYPOINT:
    00768           this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00769           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00770           this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00771           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00772           break;
    00773
    00774         case OT_GOTO_DEPOT:
    00775           /* Remove unload and replace it with refit */
    00776           this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00777           this->HideWidget(ORDER_WIDGET_UNLOAD);
    00778           this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00779           this->HideWidget(ORDER_WIDGET_FULL_LOAD);
    00780           this->ShowWidget(ORDER_WIDGET_REFIT);
    00781           this->ShowWidget(ORDER_WIDGET_SERVICE_DROPDOWN);
    00782           this->ShowWidget(ORDER_WIDGET_SERVICE);
    00783           this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    00784           break;
    00785
    00786         case OT_CONDITIONAL: {
    00787           this->HideWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00788           this->HideWidget(ORDER_WIDGET_NON_STOP);
    00789           this->HideWidget(ORDER_WIDGET_UNLOAD);
    00790           this->HideWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00791           this->HideWidget(ORDER_WIDGET_FULL_LOAD);
    00792           this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00793           this->ShowWidget(ORDER_WIDGET_COND_VARIABLE);
    00794           this->ShowWidget(ORDER_WIDGET_COND_COMPARATOR);
    00795           this->ShowWidget(ORDER_WIDGET_COND_VALUE);
    00796
    00797           OrderConditionVariable ocv = order->GetConditionVariable();
    00798           this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    00799           this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    00800
    00801           uint value = order->GetConditionValue();
    00802           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00803           SetDParam(1, value);
    00804         } break;
    00805
    00806         default: // every other orders
    00807           this->DisableWidget(ORDER_WIDGET_NON_STOP_DROPDOWN);
    00808           this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00809           this->DisableWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
    00810           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00811           this->DisableWidget(ORDER_WIDGET_UNLOAD_DROPDOWN);
    00812           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00813       }
    00814     }
    00815
    00816     SetDParam(0, this->vehicle->index);
    00817     this->DrawWidgets();
    00818
    00819     int y = 15;
    00820
    00821     int i = this->vscroll.pos;
    00822     order = GetVehicleOrder(this->vehicle, i);
    00823     StringID str;
    00824     while (order != NULL) {
    00825       /* Don't draw anything if it extends past the end of the window. */
    00826       if (i - this->vscroll.pos >= this->vscroll.cap) break;
    00827
    00828       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, this->widget[ORDER_WIDGET_ORDER_LIST].right - 4);
    00829       y += 10;
    00830
    00831       i++;
    00832       order = order->next;
    00833     }
    00834
    00835     if (i - this->vscroll.pos < this->vscroll.cap) {
    00836       str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
    00837       DrawString(2, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
    00838     }
    00839   }
    00840
    00841   virtual void OnClick(Point pt, int widget)
    00842   {
    00843     switch (widget) {
    00844       case ORDER_WIDGET_ORDER_LIST: {
    00845         ResetObjectToPlace();
    00846
    00847         int sel = this->GetOrderFromPt(pt.y);
    00848
    00849         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    00850           const Order *ord = GetVehicleOrder(this->vehicle, sel);
    00851           TileIndex xy = INVALID_TILE;
    00852
    00853           switch (ord->GetType()) {
    00854             case OT_GOTO_STATION:  xy = GetStation(ord->GetDestination())->xy ; break;
    00855             case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->GetDestination())->xy; break;
    00856             case OT_GOTO_DEPOT:
    00857               if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
    00858               xy = (this->vehicle->type == VEH_AIRCRAFT) ?  GetStation(ord->GetDestination())->xy : GetDepot(ord->GetDestination())->xy;
    00859               break;
    00860             default:
    00861               break;
    00862           }
    00863
    00864           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    00865           return;
    00866         }
    00867
    00868         /* This order won't be selected any more, close all child windows and dropdowns */
    00869         this->DeleteChildWindows();
    00870         HideDropDownMenu(this);
    00871
    00872         if (sel == INVALID_ORDER || sel == this->selected_order) {
    00873           /* Deselect clicked order */
    00874           this->selected_order = -1;
    00875         } else {
    00876           /* Select clicked order */
    00877           this->selected_order = sel;
    00878
    00879           if (this->vehicle->owner == _local_company) {
    00880             /* Activate drag and drop */
    00881             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, VHM_DRAG, this);
    00882           }
    00883         }
    00884
    00885         this->SetDirty();
    00886       } break;
    00887
    00888       case ORDER_WIDGET_SKIP:
    00889         OrderClick_Skip(this, 0);
    00890         break;
    00891
    00892       case ORDER_WIDGET_DELETE:
    00893         OrderClick_Delete(this, 0);
    00894         break;
    00895
    00896       case ORDER_WIDGET_NON_STOP:
    00897         OrderClick_Nonstop(this, -1);
    00898         break;
    00899
    00900       case ORDER_WIDGET_NON_STOP_DROPDOWN: {
    00901         const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00902         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));
    00903       } break;
    00904
    00905       case ORDER_WIDGET_GOTO:
    00906         OrderClick_Goto(this, 0);
    00907         break;
    00908
    00909       case ORDER_WIDGET_GOTO_DROPDOWN:
    00910         ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO_DROPDOWN, 0, 0);
    00911         break;
    00912
    00913       case ORDER_WIDGET_FULL_LOAD:
    00914         OrderClick_FullLoad(this, -1);
    00915         break;
    00916
    00917       case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
    00918         ShowDropDownMenu(this, _order_full_load_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
    00919         break;
    00920
    00921       case ORDER_WIDGET_UNLOAD:
    00922         OrderClick_Unload(this, -1);
    00923         break;
    00924
    00925       case ORDER_WIDGET_UNLOAD_DROPDOWN:
    00926         ShowDropDownMenu(this, _order_unload_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
    00927         break;
    00928
    00929       case ORDER_WIDGET_REFIT:
    00930         OrderClick_Refit(this, 0);
    00931         break;
    00932
    00933       case ORDER_WIDGET_SERVICE:
    00934         OrderClick_Service(this, -1);
    00935         break;
    00936
    00937       case ORDER_WIDGET_SERVICE_DROPDOWN:
    00938         ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
    00939         break;
    00940
    00941       case ORDER_WIDGET_TIMETABLE_VIEW:
    00942         ShowTimetableWindow(this->vehicle);
    00943         break;
    00944
    00945       case ORDER_WIDGET_COND_VARIABLE:
    00946         ShowDropDownMenu(this, _order_conditional_variable, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
    00947         break;
    00948
    00949       case ORDER_WIDGET_COND_COMPARATOR: {
    00950         const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00951         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    00952       } break;
    00953
    00954       case ORDER_WIDGET_COND_VALUE: {
    00955         const Order *order = GetVehicleOrder(this->vehicle, this->OrderGetSel());
    00956         uint value = order->GetConditionValue();
    00957         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00958         SetDParam(0, value);
    00959         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
    00960       } break;
    00961
    00962       case ORDER_WIDGET_SHARED_ORDER_LIST:
    00963         ShowVehicleListWindow(this->vehicle);
    00964         break;
    00965     }
    00966   }
    00967
    00968   virtual void OnQueryTextFinished(char *str)
    00969   {
    00970     if (!StrEmpty(str)) {
    00971       VehicleOrderID sel = this->OrderGetSel();
    00972       uint value = atoi(str);
    00973
    00974       switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) {
    00975         case OCV_MAX_SPEED:
    00976           value = ConvertDisplaySpeedToSpeed(value);
    00977           break;
    00978
    00979         case OCV_RELIABILITY:
    00980         case OCV_LOAD_PERCENTAGE:
    00981           value = Clamp(value, 0, 100);
    00982
    00983         default:
    00984           break;
    00985       }
    00986       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));
    00987     }
    00988   }
    00989
    00990   virtual void OnDropdownSelect(int widget, int index)
    00991   {
    00992     switch (widget) {
    00993       case ORDER_WIDGET_NON_STOP_DROPDOWN:
    00994         OrderClick_Nonstop(this, index);
    00995         break;
    00996
    00997       case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
    00998         OrderClick_FullLoad(this, index);
    00999         break;
    01000
    01001       case ORDER_WIDGET_UNLOAD_DROPDOWN:
    01002         OrderClick_Unload(this, index);
    01003         break;
    01004
    01005       case ORDER_WIDGET_GOTO_DROPDOWN:
    01006         switch (index) {
    01007           case 0: OrderClick_Goto(this, 0); break;
    01008           case 1: OrderClick_NearestDepot(this, 0); break;
    01009           case 2: OrderClick_Conditional(this, 0); break;
    01010           default: NOT_REACHED();
    01011         }
    01012         break;
    01013
    01014       case ORDER_WIDGET_SERVICE_DROPDOWN:
    01015         OrderClick_Service(this, index);
    01016         break;
    01017
    01018       case ORDER_WIDGET_COND_VARIABLE:
    01019         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));
    01020         break;
    01021
    01022       case ORDER_WIDGET_COND_COMPARATOR:
    01023         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));
    01024         break;
    01025     }
    01026   }
    01027
    01028   virtual void OnDragDrop(Point pt, int widget)
    01029   {
    01030     switch (widget) {
    01031       case ORDER_WIDGET_ORDER_LIST: {
    01032         int from_order = this->OrderGetSel();
    01033         int to_order = this->GetOrderFromPt(pt.y);
    01034
    01035         if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
    01036             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) {
    01037           this->selected_order = -1;
    01038         }
    01039       } break;
    01040
    01041       case ORDER_WIDGET_DELETE:
    01042         OrderClick_Delete(this, 0);
    01043         break;
    01044     }
    01045
    01046     ResetObjectToPlace();
    01047   }
    01048
    01049   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01050   {
    01051     static const KeyToEvent keytoevent[] = {
    01052       {'D', OrderClick_Skip},
    01053       {'F', OrderClick_Delete},
    01054       {'G', OrderClick_Goto},
    01055       {'H', OrderClick_Nonstop},
    01056       {'J', OrderClick_FullLoad},
    01057       {'K', OrderClick_Unload},
    01058       //('?', OrderClick_Service},
    01059     };
    01060
    01061     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01062
    01063     for (uint i = 0; i < lengthof(keytoevent); i++) {
    01064       if (keycode == keytoevent[i].keycode) {
    01065         keytoevent[i].proc(this, -1);
    01066         return ES_HANDLED;
    01067       }
    01068     }
    01069     return ES_NOT_HANDLED;
    01070   }
    01071
    01072   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01073   {
    01074     if (this->goto_type == OPOS_GOTO) {
    01075       /* check if we're clicking on a vehicle first.. clone orders in that case. */
    01076       const Vehicle *v = CheckMouseOverVehicle();
    01077       if (v != NULL && this->HandleOrderVehClick(v)) return;
    01078
    01079       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01080       if (!cmd.IsValid()) return;
    01081
    01082       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))) {
    01083         /* With quick goto the Go To button stays active */
    01084         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01085       }
    01086     }
    01087   }
    01088
    01089   virtual void OnPlaceObjectAbort()
    01090   {
    01091     if (this->goto_type == OPOS_CONDITIONAL) {
    01092       this->goto_type = OPOS_GOTO;
    01093       if (_cursor.pos.x >= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].left) &&
    01094           _cursor.pos.y >= (this->top  + this->widget[ORDER_WIDGET_ORDER_LIST].top) &&
    01095           _cursor.pos.x <= (this->left + this->widget[ORDER_WIDGET_ORDER_LIST].right) &&
    01096           _cursor.pos.y <= (this->top  + this->widget[ORDER_WIDGET_ORDER_LIST].bottom)) {
    01097         int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01098         if (order_id != INVALID_ORDER) {
    01099           Order order;
    01100           order.next = NULL;
    01101           order.index = 0;
    01102           order.MakeConditional(order_id);
    01103
    01104           DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER));
    01105         }
    01106       }
    01107     }
    01108     this->RaiseWidget(ORDER_WIDGET_GOTO);
    01109     this->InvalidateWidget(ORDER_WIDGET_GOTO);
    01110   }
    01111
    01112   virtual void OnMouseLoop()
    01113   {
    01114     const Vehicle *v = _place_clicked_vehicle;
    01115     /*
    01116      * Check if we clicked on a vehicle
    01117      * and if the GOTO button of this window is pressed
    01118      * This is because of all open order windows WE_MOUSELOOP is called
    01119      * and if you have 3 windows open, and this check is not done
    01120      * the order is copied to the last open window instead of the
    01121      * one where GOTO is enabled
    01122      */
    01123     if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    01124       _place_clicked_vehicle = NULL;
    01125       this->HandleOrderVehClick(v);
    01126     }
    01127   }
    01128
    01129   virtual void OnResize(Point new_size, Point delta)
    01130   {
    01131     /* Update the scroll + matrix */
    01132     this->vscroll.cap = (this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
    01133   }
    01134
    01135   virtual void OnTimeout()
    01136   {
    01137     /* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
    01138     for (uint i = 0; i < this->widget_count; i++) {
    01139       if (this->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
    01140         this->RaiseWidget(i);
    01141         this->InvalidateWidget(i);
    01142       }
    01143     }
    01144   }
    01145 };
    01146
    01150 static const Widget _orders_train_widgets[] = {
    01151   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01152   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,         STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01153   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW,      STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01154   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,                STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01155
    01156   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                     STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01157
    01158   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01159
    01160   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    88,    99, STR_8823_SKIP,           STR_8853_SKIP_THE_CURRENT_ORDER},     // ORDER_WIDGET_SKIP
    01161   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    88,    99, STR_8824_DELETE,         STR_8854_DELETE_THE_HIGHLIGHTED},     // ORDER_WIDGET_DELETE
    01162   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_NON_STOP},          // ORDER_WIDGET_NON_STOP_DROPDOWN
    01163   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   111,    76,    87, STR_ORDER_NON_STOP,      STR_ORDER_TOOLTIP_NON_STOP},          // ORDER_WIDGET_NON_STOP
    01164   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    88,    99, STR_EMPTY,               STR_ORDER_GO_TO_DROPDOWN_TOOLTIP},    // ORDER_WIDGET_GOTO_DROPDOWN
    01165   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    88,    99, STR_8826_GO_TO,          STR_8856_INSERT_A_NEW_ORDER_BEFORE},  // ORDER_WIDGET_GOTO
    01166   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_FULL_LOAD},         // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01167   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   235,    76,    87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD},      // ORDER_WIDGET_FULL_LOAD
    01168   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01169   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
    01170   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
    01171   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
    01172   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
    01173
    01174   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
    01175   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
    01176   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_CONDITIONAL_VALUE,   STR_ORDER_CONDITIONAL_VALUE_TOOLTIP},      // ORDER_WIDGET_COND_VALUE
    01177
    01178   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,   372,   373,    76,    99, 0x0,                     STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01179   { 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
    01180
    01181   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    88,    99, 0x0,                     STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01182   {   WIDGETS_END},
    01183 };
    01184
    01185 static const WindowDesc _orders_train_desc(
    01186   WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
    01187   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01188   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    01189   _orders_train_widgets
    01190 );
    01191
    01195 static const Widget _orders_widgets[] = {
    01196   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01197   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,         STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01198   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW,      STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01199   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,                STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01200
    01201   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                     STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01202
    01203   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01204
    01205   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    88,    99, STR_8823_SKIP,           STR_8853_SKIP_THE_CURRENT_ORDER},     // ORDER_WIDGET_SKIP
    01206   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    88,    99, STR_8824_DELETE,         STR_8854_DELETE_THE_HIGHLIGHTED},     // ORDER_WIDGET_DELETE
    01207   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                     0x0},                                 // ORDER_WIDGET_NON_STOP_DROPDOWN
    01208   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                     0x0},                                 // ORDER_WIDGET_NON_STOP
    01209   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    88,    99, STR_EMPTY,               STR_ORDER_GO_TO_DROPDOWN_TOOLTIP},    // ORDER_WIDGET_GOTO_DROPDOWN
    01210   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    88,    99, STR_8826_GO_TO,          STR_8856_INSERT_A_NEW_ORDER_BEFORE},  // ORDER_WIDGET_GOTO
    01211   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   185,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_FULL_LOAD},         // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01212   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   173,    76,    87, STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD},      // ORDER_WIDGET_FULL_LOAD
    01213   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01214   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
    01215   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   185,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
    01216   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
    01217   {    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
    01218
    01219   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
    01220   {   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
    01221   { WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_CONDITIONAL_VALUE,   STR_ORDER_CONDITIONAL_VALUE_TOOLTIP},      // ORDER_WIDGET_COND_VALUE
    01222
    01223   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,   372,   373,    76,    99, 0x0,                     STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01224   { 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
    01225
    01226   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    88,    99, 0x0,                     STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01227   {   WIDGETS_END},
    01228 };
    01229
    01230 static const WindowDesc _orders_desc(
    01231   WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
    01232   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01233   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    01234   _orders_widgets
    01235 );
    01236
    01240 static const Widget _other_orders_widgets[] = {
    01241   {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_GREY,     0,    10,     0,    13, STR_00C5,           STR_018B_CLOSE_WINDOW},               // ORDER_WIDGET_CLOSEBOX
    01242   {    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,    11,   373,     0,    13, STR_8829_ORDERS,    STR_018C_WINDOW_TITLE_DRAG_THIS},     // ORDER_WIDGET_CAPTION
    01243   { WWT_PUSHTXTBTN,   RESIZE_LR,     COLOUR_GREY,   313,   373,     0,    13, STR_TIMETABLE_VIEW, STR_TIMETABLE_VIEW_TOOLTIP},          // ORDER_WIDGET_TIMETABLE_VIEW
    01244   {  WWT_STICKYBOX,   RESIZE_LR,     COLOUR_GREY,   374,   385,     0,    13, STR_NULL,           STR_STICKY_BUTTON},                   // ORDER_WIDGET_STICKY
    01245
    01246   {      WWT_PANEL,   RESIZE_RB,     COLOUR_GREY,     0,   373,    14,    75, 0x0,                STR_8852_ORDERS_LIST_CLICK_ON_ORDER}, // ORDER_WIDGET_ORDER_LIST
    01247
    01248   {  WWT_SCROLLBAR,   RESIZE_LRB,    COLOUR_GREY,   374,   385,    14,    75, 0x0,                STR_0190_SCROLL_BAR_SCROLLS_LIST},    // ORDER_WIDGET_SCROLLBAR
    01249
    01250   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SKIP
    01251   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_DELETE
    01252   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_NON_STOP_DROPDOWN
    01253   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_NON_STOP
    01254   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_GOTO_DROPDOWN
    01255   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_GOTO
    01256   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_FULL_LOAD_DROPDOWN
    01257   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_FULL_LOAD
    01258   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD_DROPDOWN
    01259   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD
    01260   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_REFIT
    01261   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE_DROPDOWN
    01262   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE
    01263
    01264   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_VARIABLE
    01265   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_COMPARATOR
    01266   {      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_VALUE
    01267
    01268   {      WWT_PANEL,   RESIZE_RTB,    COLOUR_GREY,     0,   373,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_RESIZE_BAR
    01269   {      WWT_EMPTY,   RESIZE_TB,     COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SHARED_ORDER_LIST
    01270
    01271   {  WWT_RESIZEBOX,   RESIZE_LRTB,   COLOUR_GREY,   374,   385,    76,    87, 0x0,                STR_RESIZE_BUTTON},                   // ORDER_WIDGET_RESIZE
    01272   {   WIDGETS_END},
    01273 };
    01274
    01275 static const WindowDesc _other_orders_desc(
    01276   WDP_AUTO, WDP_AUTO, 386, 88, 386, 88,
    01277   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01278   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE | WDF_CONSTRUCTION,
    01279   _other_orders_widgets
    01280 );
    01281
    01282 void ShowOrdersWindow(const Vehicle *v)
    01283 {
    01284   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01285   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01286   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01287
    01288   if (v->owner != _local_company) {
    01289     new OrdersWindow(&_other_orders_desc, v);
    01290   } else {
    01291     new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
    01292   }
    01293 }