# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "command_func.h"
    00014 #include "viewport_func.h"
    00015 #include "depot_map.h"
    00016 #include "roadveh.h"
    00017 #include "timetable.h"
    00018 #include "strings_func.h"
    00019 #include "company_func.h"
    00020 #include "widgets/dropdown_type.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 "station_base.h"
    00027 #include "waypoint_base.h"
    00028 #include "core/geometry_func.hpp"
    00029 #include "hotkeys.h"
    00030 #include "aircraft.h"
    00031
    00032 #include "widgets/order_widget.h"
    00033
    00034
    00036 static const StringID _station_load_types[][5][5] = {
    00037   {
    00038     /* No refitting. */
    00039     {
    00040       STR_EMPTY,
    00041       INVALID_STRING_ID,
    00042       STR_ORDER_FULL_LOAD,
    00043       STR_ORDER_FULL_LOAD_ANY,
    00044       STR_ORDER_NO_LOAD,
    00045     }, {
    00046       STR_ORDER_UNLOAD,
    00047       INVALID_STRING_ID,
    00048       STR_ORDER_UNLOAD_FULL_LOAD,
    00049       STR_ORDER_UNLOAD_FULL_LOAD_ANY,
    00050       STR_ORDER_UNLOAD_NO_LOAD,
    00051     }, {
    00052       STR_ORDER_TRANSFER,
    00053       INVALID_STRING_ID,
    00054       STR_ORDER_TRANSFER_FULL_LOAD,
    00055       STR_ORDER_TRANSFER_FULL_LOAD_ANY,
    00056       STR_ORDER_TRANSFER_NO_LOAD,
    00057     }, {
    00058       /* Unload and transfer do not work together. */
    00059       INVALID_STRING_ID,
    00060       INVALID_STRING_ID,
    00061       INVALID_STRING_ID,
    00062       INVALID_STRING_ID,
    00063     }, {
    00064       STR_ORDER_NO_UNLOAD,
    00065       INVALID_STRING_ID,
    00066       STR_ORDER_NO_UNLOAD_FULL_LOAD,
    00067       STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
    00068       STR_ORDER_NO_UNLOAD_NO_LOAD,
    00069     }
    00070   }, {
    00071     /* With auto-refitting. No loading and auto-refitting do not work together. */
    00072     {
    00073       STR_ORDER_AUTO_REFIT,
    00074       INVALID_STRING_ID,
    00075       STR_ORDER_FULL_LOAD_REFIT,
    00076       STR_ORDER_FULL_LOAD_ANY_REFIT,
    00077       INVALID_STRING_ID,
    00078     }, {
    00079       STR_ORDER_UNLOAD_REFIT,
    00080       INVALID_STRING_ID,
    00081       STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
    00082       STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
    00083       INVALID_STRING_ID,
    00084     }, {
    00085       STR_ORDER_TRANSFER_REFIT,
    00086       INVALID_STRING_ID,
    00087       STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
    00088       STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
    00089       INVALID_STRING_ID,
    00090     }, {
    00091       /* Unload and transfer do not work together. */
    00092       INVALID_STRING_ID,
    00093       INVALID_STRING_ID,
    00094       INVALID_STRING_ID,
    00095       INVALID_STRING_ID,
    00096     }, {
    00097       STR_ORDER_NO_UNLOAD_REFIT,
    00098       INVALID_STRING_ID,
    00099       STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
    00100       STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
    00101       INVALID_STRING_ID,
    00102     }
    00103   }
    00104 };
    00105
    00106 static const StringID _order_non_stop_drowdown[] = {
    00107   STR_ORDER_GO_TO,
    00108   STR_ORDER_GO_NON_STOP_TO,
    00109   STR_ORDER_GO_VIA,
    00110   STR_ORDER_GO_NON_STOP_VIA,
    00111   INVALID_STRING_ID
    00112 };
    00113
    00114 static const StringID _order_full_load_drowdown[] = {
    00115   STR_ORDER_DROP_LOAD_IF_POSSIBLE,
    00116   STR_EMPTY,
    00117   STR_ORDER_DROP_FULL_LOAD_ALL,
    00118   STR_ORDER_DROP_FULL_LOAD_ANY,
    00119   STR_ORDER_DROP_NO_LOADING,
    00120   INVALID_STRING_ID
    00121 };
    00122
    00123 static const StringID _order_unload_drowdown[] = {
    00124   STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
    00125   STR_ORDER_DROP_UNLOAD,
    00126   STR_ORDER_DROP_TRANSFER,
    00127   STR_EMPTY,
    00128   STR_ORDER_DROP_NO_UNLOADING,
    00129   INVALID_STRING_ID
    00130 };
    00131
    00132 static const StringID _order_goto_dropdown[] = {
    00133   STR_ORDER_GO_TO,
    00134   STR_ORDER_GO_TO_NEAREST_DEPOT,
    00135   STR_ORDER_CONDITIONAL,
    00136   STR_ORDER_SHARE,
    00137   INVALID_STRING_ID
    00138 };
    00139
    00140 static const StringID _order_goto_dropdown_aircraft[] = {
    00141   STR_ORDER_GO_TO,
    00142   STR_ORDER_GO_TO_NEAREST_HANGAR,
    00143   STR_ORDER_CONDITIONAL,
    00144   STR_ORDER_SHARE,
    00145   INVALID_STRING_ID
    00146 };
    00147
    00149 static const OrderConditionVariable _order_conditional_variable[] = {
    00150   OCV_LOAD_PERCENTAGE,
    00151   OCV_RELIABILITY,
    00152   OCV_MAX_SPEED,
    00153   OCV_AGE,
    00154   OCV_REMAINING_LIFETIME,
    00155   OCV_REQUIRES_SERVICE,
    00156   OCV_UNCONDITIONALLY,
    00157 };
    00158
    00159 static const StringID _order_conditional_condition[] = {
    00160   STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
    00161   STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
    00162   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
    00163   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
    00164   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
    00165   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
    00166   STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
    00167   STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
    00168   INVALID_STRING_ID,
    00169 };
    00170
    00171 extern uint ConvertSpeedToDisplaySpeed(uint speed);
    00172 extern uint ConvertDisplaySpeedToSpeed(uint speed);
    00173
    00174 static const StringID _order_depot_action_dropdown[] = {
    00175   STR_ORDER_DROP_GO_ALWAYS_DEPOT,
    00176   STR_ORDER_DROP_SERVICE_DEPOT,
    00177   STR_ORDER_DROP_HALT_DEPOT,
    00178   INVALID_STRING_ID
    00179 };
    00180
    00181 static int DepotActionStringIndex(const Order *order)
    00182 {
    00183   if (order->GetDepotActionType() & ODATFB_HALT) {
    00184     return DA_STOP;
    00185   } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00186     return DA_SERVICE;
    00187   } else {
    00188     return DA_ALWAYS_GO;
    00189   }
    00190 }
    00191
    00192 static const StringID _order_refit_action_dropdown[] = {
    00193   STR_ORDER_DROP_REFIT_AUTO,
    00194   STR_ORDER_DROP_REFIT_AUTO_ANY,
    00195   INVALID_STRING_ID
    00196 };
    00197
    00210 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
    00211 {
    00212   bool rtl = _current_text_dir == TD_RTL;
    00213
    00214   SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
    00215   Dimension sprite_size = GetSpriteSize(sprite);
    00216   if (v->cur_real_order_index == order_index) {
    00217     DrawSprite(sprite, PAL_NONE, rtl ? right -     sprite_size.width : left,                     y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00218     DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00219   } else if (v->cur_implicit_order_index == order_index) {
    00220     DrawSprite(sprite, PAL_NONE, rtl ? right -     sprite_size.width : left,                     y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00221   }
    00222
    00223   TextColour colour = TC_BLACK;
    00224   if (order->IsType(OT_IMPLICIT)) {
    00225     colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
    00226   } else if (selected) {
    00227     colour = TC_WHITE;
    00228   }
    00229
    00230   SetDParam(0, order_index + 1);
    00231   DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
    00232
    00233   SetDParam(5, STR_EMPTY);
    00234   SetDParam(8, STR_EMPTY);
    00235
    00236   /* Check range for aircraft. */
    00237   if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
    00238     const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
    00239     if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
    00240   }
    00241
    00242   switch (order->GetType()) {
    00243     case OT_DUMMY:
    00244       SetDParam(0, STR_INVALID_ORDER);
    00245       SetDParam(1, order->GetDestination());
    00246       break;
    00247
    00248     case OT_IMPLICIT:
    00249       SetDParam(0, STR_ORDER_GO_TO_STATION);
    00250       SetDParam(1, STR_ORDER_GO_TO);
    00251       SetDParam(2, order->GetDestination());
    00252       SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
    00253       break;
    00254
    00255     case OT_GOTO_STATION: {
    00256       OrderLoadFlags load = order->GetLoadType();
    00257       OrderUnloadFlags unload = order->GetUnloadType();
    00258
    00259       SetDParam(0, STR_ORDER_GO_TO_STATION);
    00260       SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
    00261       SetDParam(2, order->GetDestination());
    00262
    00263       if (timetable) {
    00264         SetDParam(3, STR_EMPTY);
    00265
    00266         if (order->wait_time > 0) {
    00267           SetDParam(5, STR_TIMETABLE_STAY_FOR);
    00268           SetTimetableParams(6, 7, order->wait_time);
    00269         }
    00270       } else {
    00271         SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
    00272         if (order->IsRefit()) {
    00273           SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
    00274         }
    00275         if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
    00276           SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
    00277         }
    00278       }
    00279       break;
    00280     }
    00281
    00282     case OT_GOTO_DEPOT:
    00283       if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00284         SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
    00285         if (v->type == VEH_AIRCRAFT) {
    00286           SetDParam(2, STR_ORDER_NEAREST_HANGAR);
    00287           SetDParam(3, STR_EMPTY);
    00288         } else {
    00289           SetDParam(2, STR_ORDER_NEAREST_DEPOT);
    00290           SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
    00291         }
    00292       } else {
    00293         SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
    00294         SetDParam(2, v->type);
    00295         SetDParam(3, order->GetDestination());
    00296       }
    00297
    00298       if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00299         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
    00300       } else {
    00301         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
    00302       }
    00303
    00304       if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
    00305         SetDParam(5, STR_ORDER_STOP_ORDER);
    00306       }
    00307
    00308       if (!timetable && order->IsRefit()) {
    00309         SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
    00310         SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
    00311       }
    00312       break;
    00313
    00314     case OT_GOTO_WAYPOINT:
    00315       SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
    00316       SetDParam(1, order->GetDestination());
    00317       break;
    00318
    00319     case OT_CONDITIONAL:
    00320       SetDParam(1, order->GetConditionSkipToOrder() + 1);
    00321       if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
    00322         SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
    00323       } else {
    00324         OrderConditionComparator occ = order->GetConditionComparator();
    00325         SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
    00326         SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
    00327         SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
    00328
    00329         uint value = order->GetConditionValue();
    00330         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00331         SetDParam(4, value);
    00332       }
    00333
    00334       if (timetable && order->wait_time > 0) {
    00335         SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR);
    00336         SetTimetableParams(6, 7, order->wait_time);
    00337       } else {
    00338         SetDParam(5, STR_EMPTY);
    00339       }
    00340       break;
    00341
    00342     default: NOT_REACHED();
    00343   }
    00344
    00345   DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
    00346 }
    00347
    00348
    00349 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
    00350 {
    00351   Order order;
    00352   order.next  = NULL;
    00353   order.index = 0;
    00354
    00355   /* check depot first */
    00356   switch (GetTileType(tile)) {
    00357     case MP_RAILWAY:
    00358       if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
    00359         if (IsRailDepot(tile)) {
    00360           order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00361               _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00362           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00363           return order;
    00364         }
    00365       }
    00366       break;
    00367
    00368     case MP_ROAD:
    00369       if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
    00370         order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00371             _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00372         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00373         return order;
    00374       }
    00375       break;
    00376
    00377     case MP_STATION:
    00378       if (v->type != VEH_AIRCRAFT) break;
    00379       if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
    00380         order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00381         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00382         return order;
    00383       }
    00384       break;
    00385
    00386     case MP_WATER:
    00387       if (v->type != VEH_SHIP) break;
    00388       if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
    00389         order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00390         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00391         return order;
    00392       }
    00393       break;
    00394
    00395     default:
    00396       break;
    00397   }
    00398
    00399   /* check waypoint */
    00400   if (IsRailWaypointTile(tile) &&
    00401       v->type == VEH_TRAIN &&
    00402       IsTileOwner(tile, _local_company)) {
    00403     order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
    00404     if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
    00405     return order;
    00406   }
    00407
    00408   if ((IsBuoyTile(tile) && v->type == VEH_SHIP) || (IsRailWaypointTile(tile) && v->type == VEH_TRAIN)) {
    00409     order.MakeGoToWaypoint(GetStationIndex(tile));
    00410     return order;
    00411   }
    00412
    00413   if (IsTileType(tile, MP_STATION)) {
    00414     StationID st_index = GetStationIndex(tile);
    00415     const Station *st = Station::Get(st_index);
    00416
    00417     if (st->owner == _local_company || st->owner == OWNER_NONE) {
    00418       byte facil;
    00419       (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
    00420       (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
    00421       (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
    00422       (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
    00423       (facil = FACIL_TRUCK_STOP, 1);
    00424       if (st->facilities & facil) {
    00425         order.MakeGoToStation(st_index);
    00426         if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
    00427         if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00428         order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
    00429         return order;
    00430       }
    00431     }
    00432   }
    00433
    00434   /* not found */
    00435   order.Free();
    00436   return order;
    00437 }
    00438
    00479 struct OrdersWindow : public Window {
    00480 private:
    00482   enum OrderPlaceObjectState {
    00483     OPOS_GOTO,
    00484     OPOS_CONDITIONAL,
    00485     OPOS_SHARE,
    00486   };
    00487
    00489   enum DisplayPane {
    00490     /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
    00491     DP_GROUNDVEHICLE_ROW_NORMAL      = 0,
    00492     DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1,
    00493
    00494     /* WID_O_SEL_TOP_LEFT */
    00495     DP_LEFT_LOAD       = 0,
    00496     DP_LEFT_REFIT      = 1,
    00497
    00498     /* WID_O_SEL_TOP_MIDDLE */
    00499     DP_MIDDLE_UNLOAD   = 0,
    00500     DP_MIDDLE_SERVICE  = 1,
    00501
    00502     /* WID_O_SEL_TOP_RIGHT */
    00503     DP_RIGHT_EMPTY     = 0,
    00504     DP_RIGHT_REFIT     = 1,
    00505
    00506     /* WID_O_SEL_TOP_ROW */
    00507     DP_ROW_LOAD        = 0,
    00508     DP_ROW_DEPOT       = 1,
    00509     DP_ROW_CONDITIONAL = 2,
    00510
    00511     /* WID_O_SEL_BOTTOM_MIDDLE */
    00512     DP_BOTTOM_MIDDLE_DELETE       = 0,
    00513     DP_BOTTOM_MIDDLE_STOP_SHARING = 1,
    00514   };
    00515
    00516   int selected_order;
    00517   VehicleOrderID order_over;
    00518   OrderPlaceObjectState goto_type;
    00519   const Vehicle *vehicle;
    00520   Scrollbar *vscroll;
    00521   bool can_do_autorefit;
    00522
    00528   VehicleOrderID OrderGetSel() const
    00529   {
    00530     int num = this->selected_order;
    00531     return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
    00532   }
    00533
    00542   VehicleOrderID GetOrderFromPt(int y)
    00543   {
    00544     NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
    00545     int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
    00546
    00547     if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
    00548
    00549     sel += this->vscroll->GetPosition();
    00550
    00551     return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
    00552   }
    00553
    00558   void OrderClick_Goto(int i)
    00559   {
    00560     this->SetWidgetDirty(WID_O_GOTO);
    00561     this->ToggleWidgetLoweredState(WID_O_GOTO);
    00562     if (this->IsWidgetLowered(WID_O_GOTO)) {
    00563       SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT | HT_VEHICLE, this);
    00564       this->goto_type = OPOS_GOTO;
    00565     } else {
    00566       ResetObjectToPlace();
    00567     }
    00568   }
    00569
    00574   void OrderClick_FullLoad(int load_type)
    00575   {
    00576     VehicleOrderID sel_ord = this->OrderGetSel();
    00577     const Order *order = this->vehicle->GetOrder(sel_ord);
    00578
    00579     if (order == NULL || order->GetLoadType() == load_type) return;
    00580
    00581     if (load_type < 0) {
    00582       load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
    00583     }
    00584     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00585   }
    00586
    00590   void OrderHotkey_NoLoad(int i)
    00591   {
    00592     this->OrderClick_FullLoad(OLFB_NO_LOAD);
    00593   }
    00594
    00598   void OrderClick_Service(int i)
    00599   {
    00600     VehicleOrderID sel_ord = this->OrderGetSel();
    00601
    00602     if (i < 0) {
    00603       const Order *order = this->vehicle->GetOrder(sel_ord);
    00604       if (order == NULL) return;
    00605       i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
    00606     }
    00607     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00608   }
    00609
    00614   void OrderClick_NearestDepot(int i)
    00615   {
    00616     Order order;
    00617     order.next = NULL;
    00618     order.index = 0;
    00619     order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
    00620         _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00621     order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
    00622
    00623     DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    00624   }
    00625
    00630   void OrderClick_Conditional(int i)
    00631   {
    00632     this->LowerWidget(WID_O_GOTO);
    00633     this->SetWidgetDirty(WID_O_GOTO);
    00634     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_NONE, this);
    00635     this->goto_type = OPOS_CONDITIONAL;
    00636   }
    00637
    00642   void OrderClick_Share(int i)
    00643   {
    00644     this->LowerWidget(WID_O_GOTO);
    00645     this->SetWidgetDirty(WID_O_GOTO);
    00646     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_VEHICLE, this);
    00647     this->goto_type = OPOS_SHARE;
    00648   }
    00649
    00653   void OrderClick_Unload(int unload_type)
    00654   {
    00655     VehicleOrderID sel_ord = this->OrderGetSel();
    00656     const Order *order = this->vehicle->GetOrder(sel_ord);
    00657
    00658     if (order == NULL || order->GetUnloadType() == unload_type) return;
    00659
    00660     if (unload_type < 0) {
    00661       unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
    00662     }
    00663
    00664     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00665
    00666     /* Transfer orders with leave empty as default */
    00667     if (unload_type == OUFB_TRANSFER) {
    00668       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
    00669       this->SetWidgetDirty(WID_O_FULL_LOAD);
    00670     }
    00671   }
    00672
    00676   void OrderHotkey_Transfer(int i)
    00677   {
    00678     this->OrderClick_Unload(OUFB_TRANSFER);
    00679   }
    00680
    00684   void OrderHotkey_NoUnload(int i)
    00685   {
    00686     this->OrderClick_Unload(OUFB_NO_UNLOAD);
    00687   }
    00688
    00693   void OrderClick_Nonstop(int non_stop)
    00694   {
    00695     if (!this->vehicle->IsGroundVehicle()) return;
    00696
    00697     VehicleOrderID sel_ord = this->OrderGetSel();
    00698     const Order *order = this->vehicle->GetOrder(sel_ord);
    00699
    00700     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00701
    00702     /* Keypress if negative, so 'toggle' to the next */
    00703     if (non_stop < 0) {
    00704       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00705     }
    00706
    00707     this->SetWidgetDirty(WID_O_NON_STOP);
    00708     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00709   }
    00710
    00716   void OrderClick_Skip(int i)
    00717   {
    00718     /* Don't skip when there's nothing to skip */
    00719     if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
    00720     if (this->vehicle->GetNumOrders() <= 1) return;
    00721
    00722     DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
    00723         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
    00724   }
    00725
    00730   void OrderClick_Delete(int i)
    00731   {
    00732     /* When networking, move one order lower */
    00733     int selected = this->selected_order + (int)_networking;
    00734
    00735     if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
    00736       this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
    00737       this->UpdateButtonState();
    00738     }
    00739   }
    00740
    00748   void OrderClick_StopSharing(int i)
    00749   {
    00750     /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
    00751     if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
    00752     /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
    00753     if (_ctrl_pressed) {
    00754       this->OrderClick_Delete(0);
    00755       return;
    00756     }
    00757
    00758     /* Get another vehicle that share orders with this vehicle. */
    00759     Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
    00760     /* Copy the order list of the other vehicle. */
    00761     if (DoCommandP(this->vehicle->tile, this->vehicle->index | CO_COPY << 30, other_shared->index, CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST))) {
    00762       this->UpdateButtonState();
    00763     }
    00764   }
    00765
    00772   void OrderClick_Refit(int i, bool auto_refit)
    00773   {
    00774     if (_ctrl_pressed) {
    00775       /* Cancel refitting */
    00776       DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00777     } else {
    00778       if (i == 1) { // Auto-refit to available cargo type.
    00779         DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
    00780       } else {
    00781         ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
    00782       }
    00783     }
    00784   }
    00785
    00787   void UpdateAutoRefitState()
    00788   {
    00789     this->can_do_autorefit = false;
    00790     for (const Vehicle *w = this->vehicle; w != NULL; w = w->Next()) {
    00791       if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
    00792     }
    00793   }
    00794
    00795 public:
    00796   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window()
    00797   {
    00798     this->vehicle = v;
    00799
    00800     this->CreateNestedTree(desc);
    00801     this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
    00802     this->FinishInitNested(desc, v->index);
    00803     if (v->owner == _local_company) {
    00804       this->DisableWidget(WID_O_EMPTY);
    00805     }
    00806
    00807     this->selected_order = -1;
    00808     this->order_over = INVALID_VEH_ORDER_ID;
    00809     this->owner = v->owner;
    00810
    00811     this->UpdateAutoRefitState();
    00812
    00813     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00814       /* If there are less than 2 station, make Go To active. */
    00815       int station_orders = 0;
    00816       const Order *order;
    00817       FOR_VEHICLE_ORDERS(v, order) {
    00818         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00819       }
    00820
    00821       if (station_orders < 2) this->OrderClick_Goto(0);
    00822     }
    00823     this->OnInvalidateData(VIWD_MODIFY_ORDERS);
    00824   }
    00825
    00826   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00827   {
    00828     switch (widget) {
    00829       case WID_O_ORDER_LIST:
    00830         resize->height = FONT_HEIGHT_NORMAL;
    00831         size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00832         break;
    00833
    00834       case WID_O_COND_VARIABLE: {
    00835         Dimension d = {0, 0};
    00836         for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
    00837           d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
    00838         }
    00839         d.width += padding.width;
    00840         d.height += padding.height;
    00841         *size = maxdim(*size, d);
    00842         break;
    00843       }
    00844
    00845       case WID_O_COND_COMPARATOR: {
    00846         Dimension d = {0, 0};
    00847         for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
    00848           d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
    00849         }
    00850         d.width += padding.width;
    00851         d.height += padding.height;
    00852         *size = maxdim(*size, d);
    00853         break;
    00854       }
    00855     }
    00856   }
    00857
    00863   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00864   {
    00865     VehicleOrderID from = INVALID_VEH_ORDER_ID;
    00866     VehicleOrderID to   = INVALID_VEH_ORDER_ID;
    00867
    00868     switch (data) {
    00869       case VIWD_AUTOREPLACE:
    00870         /* Autoreplace replaced the vehicle */
    00871         this->vehicle = Vehicle::Get(this->window_number);
    00872         /* FALL THROUGH */
    00873
    00874       case VIWD_CONSIST_CHANGED:
    00875         /* Vehicle composition was changed. */
    00876         this->UpdateAutoRefitState();
    00877         break;
    00878
    00879       case VIWD_REMOVE_ALL_ORDERS:
    00880         /* Removed / replaced all orders (after deleting / sharing) */
    00881         if (this->selected_order == -1) break;
    00882
    00883         this->DeleteChildWindows();
    00884         HideDropDownMenu(this);
    00885         this->selected_order = -1;
    00886         break;
    00887
    00888       case VIWD_MODIFY_ORDERS:
    00889         /* Some other order changes */
    00890         break;
    00891
    00892       default:
    00893         if (data < 0) break;
    00894
    00895         if (gui_scope) break; // only do this once; from command scope
    00896         from = GB(data, 0, 8);
    00897         to   = GB(data, 8, 8);
    00898         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00899          * the order is being created / removed */
    00900         if (this->selected_order == -1) break;
    00901
    00902         if (from == to) break; // no need to change anything
    00903
    00904         if (from != this->selected_order) {
    00905           /* Moving from preceding order? */
    00906           this->selected_order -= (int)(from <= this->selected_order);
    00907           /* Moving to   preceding order? */
    00908           this->selected_order += (int)(to   <= this->selected_order);
    00909           break;
    00910         }
    00911
    00912         /* Now we are modifying the selected order */
    00913         if (to == INVALID_VEH_ORDER_ID) {
    00914           /* Deleting selected order */
    00915           this->DeleteChildWindows();
    00916           HideDropDownMenu(this);
    00917           this->selected_order = -1;
    00918           break;
    00919         }
    00920
    00921         /* Moving selected order */
    00922         this->selected_order = to;
    00923         break;
    00924     }
    00925
    00926     this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
    00927     if (gui_scope) this->UpdateButtonState();
    00928
    00929     /* Scroll to the new order. */
    00930     if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
    00931       this->vscroll->ScrollTowards(to);
    00932     }
    00933   }
    00934
    00935   void UpdateButtonState()
    00936   {
    00937     if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
    00938
    00939     bool shared_orders = this->vehicle->IsOrderListShared();
    00940     VehicleOrderID sel = this->OrderGetSel();
    00941     const Order *order = this->vehicle->GetOrder(sel);
    00942
    00943     /* Second row. */
    00944     /* skip */
    00945     this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
    00946
    00947     /* delete / stop sharing */
    00948     NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
    00949     if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
    00950       /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
    00951       delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
    00952     } else {
    00953       /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
    00954       delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
    00955       this->SetWidgetDisabledState(WID_O_DELETE,
    00956         (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00957
    00958       /* Set the tooltip of the 'delete' button depending on whether the
    00959        * 'End of Orders' order or a regular order is selected. */
    00960       NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
    00961       if (this->selected_order == this->vehicle->GetNumOrders()) {
    00962         nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
    00963       } else {
    00964         nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
    00965       }
    00966     }
    00967
    00968     /* First row. */
    00969     this->RaiseWidget(WID_O_FULL_LOAD);
    00970     this->RaiseWidget(WID_O_UNLOAD);
    00971     this->RaiseWidget(WID_O_SERVICE);
    00972
    00973     /* Selection widgets. */
    00974     /* Train or road vehicle. */
    00975     NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
    00976     NWidgetStacked *left_sel      = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
    00977     NWidgetStacked *middle_sel    = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
    00978     NWidgetStacked *right_sel     = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
    00979     /* Ship or airplane. */
    00980     NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
    00981     assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
    00982
    00983
    00984     if (order == NULL) {
    00985       if (row_sel != NULL) {
    00986         row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00987       } else {
    00988         train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    00989         left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    00990         middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    00991         right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    00992         this->DisableWidget(WID_O_NON_STOP);
    00993         this->RaiseWidget(WID_O_NON_STOP);
    00994       }
    00995       this->DisableWidget(WID_O_FULL_LOAD);
    00996       this->DisableWidget(WID_O_UNLOAD);
    00997       this->DisableWidget(WID_O_REFIT_DROPDOWN);
    00998     } else {
    00999       this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    01000       this->SetWidgetDisabledState(WID_O_UNLOAD,    (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    01001
    01002       switch (order->GetType()) {
    01003         case OT_GOTO_STATION:
    01004           if (row_sel != NULL) {
    01005             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01006           } else {
    01007             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01008             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01009             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01010             right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
    01011             this->EnableWidget(WID_O_NON_STOP);
    01012             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01013           }
    01014           this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    01015           this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    01016
    01017           /* Can only do refitting when stopping at the destination and loading cargo. */
    01018           this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN, !this->can_do_autorefit || order->GetLoadType() == OLFB_NO_LOAD || order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION);
    01019
    01020           break;
    01021
    01022         case OT_GOTO_WAYPOINT:
    01023           if (row_sel != NULL) {
    01024             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01025           } else {
    01026             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01027             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01028             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01029             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01030             this->EnableWidget(WID_O_NON_STOP);
    01031             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01032           }
    01033           this->DisableWidget(WID_O_FULL_LOAD);
    01034           this->DisableWidget(WID_O_UNLOAD);
    01035           this->DisableWidget(WID_O_REFIT_DROPDOWN);
    01036           break;
    01037
    01038         case OT_GOTO_DEPOT:
    01039           if (row_sel != NULL) {
    01040             row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
    01041           } else {
    01042             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01043             left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
    01044             middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
    01045             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01046             this->EnableWidget(WID_O_NON_STOP);
    01047             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01048           }
    01049           /* Disable refit button if the order is no 'always go' order.
    01050            * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
    01051           this->SetWidgetDisabledState(WID_O_REFIT, (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT));
    01052           this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    01053           break;
    01054
    01055         case OT_CONDITIONAL: {
    01056           if (row_sel != NULL) {
    01057             row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
    01058           } else {
    01059             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
    01060           }
    01061           OrderConditionVariable ocv = order->GetConditionVariable();
    01062           /* Set the strings for the dropdown boxes. */
    01063           this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data   = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + (order == NULL ? 0 : ocv);
    01064           this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    01065           this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    01066           this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    01067           break;
    01068         }
    01069
    01070         default: // every other order
    01071           if (row_sel != NULL) {
    01072             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01073           } else {
    01074             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01075             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01076             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01077             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01078             this->DisableWidget(WID_O_NON_STOP);
    01079           }
    01080           this->DisableWidget(WID_O_FULL_LOAD);
    01081           this->DisableWidget(WID_O_UNLOAD);
    01082           this->DisableWidget(WID_O_REFIT_DROPDOWN);
    01083           break;
    01084       }
    01085     }
    01086
    01087     /* Disable list of vehicles with the same shared orders if there is no list */
    01088     this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
    01089
    01090     this->SetDirty();
    01091   }
    01092
    01093   virtual void OnPaint()
    01094   {
    01095     if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window.
    01096     this->DrawWidgets();
    01097   }
    01098
    01099   virtual void DrawWidget(const Rect &r, int widget) const
    01100   {
    01101     if (widget != WID_O_ORDER_LIST) return;
    01102
    01103     bool rtl = _current_text_dir == TD_RTL;
    01104     SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
    01105     int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
    01106     int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
    01107
    01108     int y = r.top + WD_FRAMERECT_TOP;
    01109     int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
    01110
    01111     int i = this->vscroll->GetPosition();
    01112     const Order *order = this->vehicle->GetOrder(i);
    01113     /* First draw the highlighting underground if it exists. */
    01114     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01115       while (order != NULL) {
    01116         /* Don't draw anything if it extends past the end of the window. */
    01117         if (!this->vscroll->IsVisible(i)) break;
    01118
    01119         if (i != this->selected_order && i == this->order_over) {
    01120           /* Highlight dragged order destination. */
    01121           int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
    01122           int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
    01123           top = max(top - 3, r.top + WD_FRAMERECT_TOP);
    01124           GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
    01125           break;
    01126         }
    01127         y += line_height;
    01128
    01129         i++;
    01130         order = order->next;
    01131       }
    01132
    01133       /* Reset counters for drawing the orders. */
    01134       y = r.top + WD_FRAMERECT_TOP;
    01135       i = this->vscroll->GetPosition();
    01136       order = this->vehicle->GetOrder(i);
    01137     }
    01138
    01139     /* Draw the orders. */
    01140     while (order != NULL) {
    01141       /* Don't draw anything if it extends past the end of the window. */
    01142       if (!this->vscroll->IsVisible(i)) break;
    01143
    01144       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
    01145       y += line_height;
    01146
    01147       i++;
    01148       order = order->next;
    01149     }
    01150
    01151     if (this->vscroll->IsVisible(i)) {
    01152       StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
    01153       DrawString(rtl ? r.left + WD_FRAMETEXT_LEFT : middle, rtl ? middle : r.right - WD_FRAMETEXT_RIGHT, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
    01154     }
    01155   }
    01156
    01157   virtual void SetStringParameters(int widget) const
    01158   {
    01159     switch (widget) {
    01160       case WID_O_COND_VALUE: {
    01161         VehicleOrderID sel = this->OrderGetSel();
    01162         const Order *order = this->vehicle->GetOrder(sel);
    01163
    01164         if (order != NULL && order->IsType(OT_CONDITIONAL)) {
    01165           uint value = order->GetConditionValue();
    01166           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01167           SetDParam(0, value);
    01168         }
    01169         break;
    01170       }
    01171
    01172       case WID_O_CAPTION:
    01173         SetDParam(0, this->vehicle->index);
    01174         break;
    01175     }
    01176   }
    01177
    01178   virtual void OnClick(Point pt, int widget, int click_count)
    01179   {
    01180     switch (widget) {
    01181       case WID_O_ORDER_LIST: {
    01182         if (this->goto_type == OPOS_CONDITIONAL) {
    01183           this->goto_type = OPOS_GOTO;
    01184           VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01185           if (order_id != INVALID_VEH_ORDER_ID) {
    01186             Order order;
    01187             order.next = NULL;
    01188             order.index = 0;
    01189             order.MakeConditional(order_id);
    01190
    01191             DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    01192           }
    01193           ResetObjectToPlace();
    01194           break;
    01195         }
    01196
    01197         VehicleOrderID sel = this->GetOrderFromPt(pt.y);
    01198
    01199         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    01200           TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
    01201           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    01202           return;
    01203         }
    01204
    01205         /* This order won't be selected any more, close all child windows and dropdowns */
    01206         this->DeleteChildWindows();
    01207         HideDropDownMenu(this);
    01208
    01209         if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
    01210           /* Deselect clicked order */
    01211           this->selected_order = -1;
    01212         } else if (sel == this->selected_order) {
    01213           if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
    01214             DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
    01215                 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
    01216                 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01217           }
    01218         } else {
    01219           /* Select clicked order */
    01220           this->selected_order = sel;
    01221
    01222           if (this->vehicle->owner == _local_company) {
    01223             /* Activate drag and drop */
    01224             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
    01225           }
    01226         }
    01227
    01228         this->UpdateButtonState();
    01229         break;
    01230       }
    01231
    01232       case WID_O_SKIP:
    01233         this->OrderClick_Skip(0);
    01234         break;
    01235
    01236       case WID_O_DELETE:
    01237         this->OrderClick_Delete(0);
    01238         break;
    01239
    01240       case WID_O_STOP_SHARING:
    01241         this->OrderClick_StopSharing(0);
    01242         break;
    01243
    01244       case WID_O_NON_STOP:
    01245         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01246           this->OrderClick_Nonstop(-1);
    01247         } else {
    01248           const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01249           ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
    01250                           o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
    01251         }
    01252         break;
    01253
    01254       case WID_O_GOTO:
    01255         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01256           this->OrderClick_Goto(0);
    01257         } else {
    01258           ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, WID_O_GOTO, 0, 0);
    01259         }
    01260         break;
    01261
    01262       case WID_O_FULL_LOAD:
    01263         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01264           this->OrderClick_FullLoad(-1);
    01265         } else {
    01266           ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
    01267         }
    01268         break;
    01269
    01270       case WID_O_UNLOAD:
    01271         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01272           this->OrderClick_Unload(-1);
    01273         } else {
    01274           ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
    01275         }
    01276         break;
    01277
    01278       case WID_O_REFIT:
    01279         this->OrderClick_Refit(0, false);
    01280         break;
    01281
    01282       case WID_O_SERVICE:
    01283         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01284           this->OrderClick_Service(-1);
    01285         } else {
    01286           ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
    01287         }
    01288         break;
    01289
    01290       case WID_O_REFIT_DROPDOWN:
    01291         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01292           this->OrderClick_Refit(0, true);
    01293         } else {
    01294           ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
    01295         }
    01296         break;
    01297
    01298       case WID_O_TIMETABLE_VIEW:
    01299         ShowTimetableWindow(this->vehicle);
    01300         break;
    01301
    01302       case WID_O_COND_VARIABLE: {
    01303         DropDownList *list = new DropDownList();
    01304         for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
    01305           list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false));
    01306         }
    01307         ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
    01308         break;
    01309       }
    01310
    01311       case WID_O_COND_COMPARATOR: {
    01312         const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01313         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    01314         break;
    01315       }
    01316
    01317       case WID_O_COND_VALUE: {
    01318         const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
    01319         uint value = order->GetConditionValue();
    01320         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01321         SetDParam(0, value);
    01322         ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
    01323         break;
    01324       }
    01325
    01326       case WID_O_SHARED_ORDER_LIST:
    01327         ShowVehicleListWindow(this->vehicle);
    01328         break;
    01329     }
    01330   }
    01331
    01332   virtual void OnQueryTextFinished(char *str)
    01333   {
    01334     if (!StrEmpty(str)) {
    01335       VehicleOrderID sel = this->OrderGetSel();
    01336       uint value = atoi(str);
    01337
    01338       switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
    01339         case OCV_MAX_SPEED:
    01340           value = ConvertDisplaySpeedToSpeed(value);
    01341           break;
    01342
    01343         case OCV_RELIABILITY:
    01344         case OCV_LOAD_PERCENTAGE:
    01345           value = Clamp(value, 0, 100);
    01346           break;
    01347
    01348         default:
    01349           break;
    01350       }
    01351       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01352     }
    01353   }
    01354
    01355   virtual void OnDropdownSelect(int widget, int index)
    01356   {
    01357     switch (widget) {
    01358       case WID_O_NON_STOP:
    01359         this->OrderClick_Nonstop(index);
    01360         break;
    01361
    01362       case WID_O_FULL_LOAD:
    01363         this->OrderClick_FullLoad(index);
    01364         break;
    01365
    01366       case WID_O_UNLOAD:
    01367         this->OrderClick_Unload(index);
    01368         break;
    01369
    01370       case WID_O_GOTO:
    01371         switch (index) {
    01372           case 0: this->OrderClick_Goto(0); break;
    01373           case 1: this->OrderClick_NearestDepot(0); break;
    01374           case 2: this->OrderClick_Conditional(0); break;
    01375           case 3: this->OrderClick_Share(0); break;
    01376           default: NOT_REACHED();
    01377         }
    01378         break;
    01379
    01380       case WID_O_SERVICE:
    01381         this->OrderClick_Service(index);
    01382         break;
    01383
    01384       case WID_O_REFIT_DROPDOWN:
    01385         this->OrderClick_Refit(index, true);
    01386         break;
    01387
    01388       case WID_O_COND_VARIABLE:
    01389         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VARIABLE | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01390         break;
    01391
    01392       case WID_O_COND_COMPARATOR:
    01393         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01394         break;
    01395     }
    01396   }
    01397
    01398   virtual void OnDragDrop(Point pt, int widget)
    01399   {
    01400     switch (widget) {
    01401       case WID_O_ORDER_LIST: {
    01402         VehicleOrderID from_order = this->OrderGetSel();
    01403         VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
    01404
    01405         if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) &&
    01406             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
    01407           this->selected_order = -1;
    01408           this->UpdateButtonState();
    01409         }
    01410         break;
    01411       }
    01412
    01413       case WID_O_DELETE:
    01414         this->OrderClick_Delete(0);
    01415         break;
    01416
    01417       case WID_O_STOP_SHARING:
    01418         this->OrderClick_StopSharing(0);
    01419         break;
    01420     }
    01421
    01422     ResetObjectToPlace();
    01423
    01424     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01425       /* End of drag-and-drop, hide dragged order destination highlight. */
    01426       this->order_over = INVALID_VEH_ORDER_ID;
    01427       this->SetWidgetDirty(WID_O_ORDER_LIST);
    01428     }
    01429   }
    01430
    01431   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01432   {
    01433     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01434
    01435     return CheckHotkeyMatch<OrdersWindow>(order_hotkeys, keycode, this) != -1 ? ES_HANDLED : ES_NOT_HANDLED;
    01436   }
    01437
    01438   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01439   {
    01440     if (this->goto_type == OPOS_GOTO) {
    01441       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01442       if (cmd.IsType(OT_NOTHING)) return;
    01443
    01444       if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
    01445         /* With quick goto the Go To button stays active */
    01446         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01447       }
    01448     }
    01449   }
    01450
    01451   virtual bool OnVehicleSelect(const Vehicle *v)
    01452   {
    01453     /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
    01454      * We disallow copying orders of other vehicles if we already have at least one order entry
    01455      * ourself as it easily copies orders of vehicles within a station when we mean the station.
    01456      * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
    01457      * TODO: give a warning message */
    01458     bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
    01459     if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
    01460
    01461     if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
    01462         share_order ? CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST))) {
    01463       this->selected_order = -1;
    01464       ResetObjectToPlace();
    01465     }
    01466     return true;
    01467   }
    01468
    01469   virtual void OnPlaceObjectAbort()
    01470   {
    01471     this->RaiseWidget(WID_O_GOTO);
    01472     this->SetWidgetDirty(WID_O_GOTO);
    01473
    01474     /* Remove drag highlighting if it exists. */
    01475     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01476       this->order_over = INVALID_VEH_ORDER_ID;
    01477       this->SetWidgetDirty(WID_O_ORDER_LIST);
    01478     }
    01479   }
    01480
    01481   virtual void OnMouseDrag(Point pt, int widget)
    01482   {
    01483     if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
    01484       /* An order is dragged.. */
    01485       VehicleOrderID from_order = this->OrderGetSel();
    01486       VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
    01487       uint num_orders = this->vehicle->GetNumOrders();
    01488
    01489       if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
    01490         if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
    01491           this->order_over = to_order;
    01492           this->SetWidgetDirty(widget);
    01493         } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
    01494           this->order_over = INVALID_VEH_ORDER_ID;
    01495           this->SetWidgetDirty(widget);
    01496         }
    01497       }
    01498     }
    01499   }
    01500
    01501   virtual void OnResize()
    01502   {
    01503     /* Update the scroll bar */
    01504     this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
    01505   }
    01506
    01507   static Hotkey<OrdersWindow> order_hotkeys[];
    01508 };
    01509
    01510 Hotkey<OrdersWindow> OrdersWindow::order_hotkeys[] = {
    01511   Hotkey<OrdersWindow>('D', "skip", 0, &OrdersWindow::OrderClick_Skip),
    01512   Hotkey<OrdersWindow>('F', "delete", 0, &OrdersWindow::OrderClick_Delete),
    01513   Hotkey<OrdersWindow>('G', "goto", 0, &OrdersWindow::OrderClick_Goto),
    01514   Hotkey<OrdersWindow>('H', "nonstop", 0, &OrdersWindow::OrderClick_Nonstop),
    01515   Hotkey<OrdersWindow>('J', "fullload", 0, &OrdersWindow::OrderClick_FullLoad),
    01516   Hotkey<OrdersWindow>('K', "unload", 0, &OrdersWindow::OrderClick_Unload),
    01517   Hotkey<OrdersWindow>((uint16)0, "nearest_depot", 0, &OrdersWindow::OrderClick_NearestDepot),
    01518   Hotkey<OrdersWindow>((uint16)0, "always_service", 0, &OrdersWindow::OrderClick_Service),
    01519   Hotkey<OrdersWindow>((uint16)0, "force_unload", 0, &OrdersWindow::OrderClick_Unload),
    01520   Hotkey<OrdersWindow>((uint16)0, "transfer", 0, &OrdersWindow::OrderHotkey_Transfer),
    01521   Hotkey<OrdersWindow>((uint16)0, "no_unload", 0, &OrdersWindow::OrderHotkey_NoUnload),
    01522   Hotkey<OrdersWindow>((uint16)0, "no_load", 0, &OrdersWindow::OrderHotkey_NoLoad),
    01523   HOTKEY_LIST_END(OrdersWindow)
    01524 };
    01525 Hotkey<OrdersWindow> *_order_hotkeys = OrdersWindow::order_hotkeys;
    01526
    01528 static const NWidgetPart _nested_orders_train_widgets[] = {
    01529   NWidget(NWID_HORIZONTAL),
    01530     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01531     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01532     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01533     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01534     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01535   EndContainer(),
    01536   NWidget(NWID_HORIZONTAL),
    01537     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01538     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01539   EndContainer(),
    01540
    01541   /* First button row. */
    01542   NWidget(NWID_HORIZONTAL),
    01543     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
    01544       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01545         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
    01546                               SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
    01547         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
    01548           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
    01549                               SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01550           NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
    01551                               SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01552         EndContainer(),
    01553         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
    01554           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
    01555                               SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01556           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
    01557                               SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01558         EndContainer(),
    01559         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
    01560           NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
    01561                               SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01562           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
    01563                               SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
    01564         EndContainer(),
    01565       EndContainer(),
    01566       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01567         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01568                               SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01569         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01570                               SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01571         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01572                               SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01573       EndContainer(),
    01574     EndContainer(),
    01575     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01576   EndContainer(),
    01577
    01578   /* Second button row. */
    01579   NWidget(NWID_HORIZONTAL),
    01580     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01581       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01582                           SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01583       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
    01584         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01585                             SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01586         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
    01587                             SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
    01588       EndContainer(),
    01589       NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01590                           SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01591     EndContainer(),
    01592     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01593   EndContainer(),
    01594 };
    01595
    01596 static const WindowDesc _orders_train_desc(
    01597   WDP_AUTO, 384, 100,
    01598   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01599   WDF_CONSTRUCTION,
    01600   _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets)
    01601 );
    01602
    01604 static const NWidgetPart _nested_orders_widgets[] = {
    01605   NWidget(NWID_HORIZONTAL),
    01606     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01607     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01608     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01609     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01610     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01611   EndContainer(),
    01612   NWidget(NWID_HORIZONTAL),
    01613     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01614     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01615   EndContainer(),
    01616
    01617   /* First button row. */
    01618   NWidget(NWID_HORIZONTAL),
    01619     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
    01620       /* Load + unload + refit buttons. */
    01621       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01622         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01623                           SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01624         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01625                           SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01626         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
    01627                           SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
    01628       EndContainer(),
    01629       /* Refit + service buttons. */
    01630       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01631         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
    01632                           SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01633         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01634                           SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01635       EndContainer(),
    01636
    01637       /* Buttons for setting a condition. */
    01638       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01639         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01640                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01641         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01642                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01643         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01644                           SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01645       EndContainer(),
    01646     EndContainer(),
    01647
    01648     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01649   EndContainer(),
    01650
    01651   /* Second button row. */
    01652   NWidget(NWID_HORIZONTAL),
    01653     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01654                       SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01655     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
    01656       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01657                           SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01658       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
    01659                           SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
    01660     EndContainer(),
    01661     NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01662                       SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01663     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01664   EndContainer(),
    01665 };
    01666
    01667 static const WindowDesc _orders_desc(
    01668   WDP_AUTO, 384, 100,
    01669   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01670   WDF_CONSTRUCTION,
    01671   _nested_orders_widgets, lengthof(_nested_orders_widgets)
    01672 );
    01673
    01675 static const NWidgetPart _nested_other_orders_widgets[] = {
    01676   NWidget(NWID_HORIZONTAL),
    01677     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01678     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01679     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01680     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01681     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01682   EndContainer(),
    01683   NWidget(NWID_HORIZONTAL),
    01684     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01685     NWidget(NWID_VERTICAL),
    01686       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01687       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01688     EndContainer(),
    01689   EndContainer(),
    01690 };
    01691
    01692 static const WindowDesc _other_orders_desc(
    01693   WDP_AUTO, 384, 86,
    01694   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01695   WDF_CONSTRUCTION,
    01696   _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets)
    01697 );
    01698
    01699 void ShowOrdersWindow(const Vehicle *v)
    01700 {
    01701   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01702   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01703   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01704
    01705   if (v->owner != _local_company) {
    01706     new OrdersWindow(&_other_orders_desc, v);
    01707   } else {
    01708     new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
    01709   }
    01710 }