# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 18605 2009-12-22 19:40:23Z alberth $ */
    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 "window_gui.h"
    00014 #include "command_func.h"
    00015 #include "viewport_func.h"
    00016 #include "gfx_func.h"
    00017 #include "depot_base.h"
    00018 #include "vehicle_base.h"
    00019 #include "vehicle_gui.h"
    00020 #include "roadveh.h"
    00021 #include "timetable.h"
    00022 #include "cargotype.h"
    00023 #include "strings_func.h"
    00024 #include "window_func.h"
    00025 #include "vehicle_func.h"
    00026 #include "company_func.h"
    00027 #include "widgets/dropdown_func.h"
    00028 #include "textbuf_gui.h"
    00029 #include "string_func.h"
    00030 #include "tilehighlight_func.h"
    00031 #include "network/network.h"
    00032 #include "station_base.h"
    00033 #include "waypoint_base.h"
    00034
    00035 #include "table/sprites.h"
    00036 #include "table/strings.h"
    00037
    00039 enum OrderWindowWidgets {
    00040   ORDER_WIDGET_CAPTION,
    00041   ORDER_WIDGET_TIMETABLE_VIEW,
    00042   ORDER_WIDGET_ORDER_LIST,
    00043   ORDER_WIDGET_SCROLLBAR,
    00044   ORDER_WIDGET_SKIP,
    00045   ORDER_WIDGET_DELETE,
    00046   ORDER_WIDGET_NON_STOP,
    00047   ORDER_WIDGET_GOTO,
    00048   ORDER_WIDGET_FULL_LOAD,
    00049   ORDER_WIDGET_UNLOAD,
    00050   ORDER_WIDGET_REFIT,
    00051   ORDER_WIDGET_SERVICE,
    00052   ORDER_WIDGET_COND_VARIABLE,
    00053   ORDER_WIDGET_COND_COMPARATOR,
    00054   ORDER_WIDGET_COND_VALUE,
    00055   ORDER_WIDGET_SEL_TOP_LEFT,
    00056   ORDER_WIDGET_SEL_TOP_MIDDLE,
    00057   ORDER_WIDGET_SEL_TOP_RIGHT,
    00058   ORDER_WIDGET_SEL_TOP_ROW,
    00059   ORDER_WIDGET_SHARED_ORDER_LIST,
    00060 };
    00061
    00063 static const StringID _station_load_types[][5] = {
    00064   {
    00065     STR_EMPTY,
    00066     INVALID_STRING_ID,
    00067     STR_ORDER_FULL_LOAD,
    00068     STR_ORDER_FULL_LOAD_ANY,
    00069     STR_ORDER_NO_LOAD,
    00070   }, {
    00071     STR_ORDER_UNLOAD,
    00072     INVALID_STRING_ID,
    00073     STR_ORDER_UNLOAD_FULL_LOAD,
    00074     STR_ORDER_UNLOAD_FULL_LOAD_ANY,
    00075     STR_ORDER_UNLOAD_NO_LOAD,
    00076   }, {
    00077     STR_ORDER_TRANSFER,
    00078     INVALID_STRING_ID,
    00079     STR_ORDER_TRANSFER_FULL_LOAD,
    00080     STR_ORDER_TRANSFER_FULL_LOAD_ANY,
    00081     STR_ORDER_TRANSFER_NO_LOAD,
    00082   }, {
    00083     /* Unload and transfer do not work together. */
    00084     INVALID_STRING_ID,
    00085     INVALID_STRING_ID,
    00086     INVALID_STRING_ID,
    00087     INVALID_STRING_ID,
    00088   }, {
    00089     STR_ORDER_NO_UNLOAD,
    00090     INVALID_STRING_ID,
    00091     STR_ORDER_NO_UNLOAD_FULL_LOAD,
    00092     STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
    00093     INVALID_STRING_ID,
    00094   }
    00095 };
    00096
    00097 static const StringID _order_non_stop_drowdown[] = {
    00098   STR_ORDER_GO_TO,
    00099   STR_ORDER_GO_NON_STOP_TO,
    00100   STR_ORDER_GO_VIA,
    00101   STR_ORDER_GO_NON_STOP_VIA,
    00102   INVALID_STRING_ID
    00103 };
    00104
    00105 static const StringID _order_full_load_drowdown[] = {
    00106   STR_ORDER_DROP_LOAD_IF_POSSIBLE,
    00107   STR_EMPTY,
    00108   STR_ORDER_DROP_FULL_LOAD_ALL,
    00109   STR_ORDER_DROP_FULL_LOAD_ANY,
    00110   STR_ORDER_DROP_NO_LOADING,
    00111   INVALID_STRING_ID
    00112 };
    00113
    00114 static const StringID _order_unload_drowdown[] = {
    00115   STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
    00116   STR_ORDER_DROP_UNLOAD,
    00117   STR_ORDER_DROP_TRANSFER,
    00118   STR_EMPTY,
    00119   STR_ORDER_DROP_NO_UNLOADING,
    00120   INVALID_STRING_ID
    00121 };
    00122
    00123 static const StringID _order_goto_dropdown[] = {
    00124   STR_ORDER_GO_TO,
    00125   STR_ORDER_GO_TO_NEAREST_DEPOT,
    00126   STR_ORDER_CONDITIONAL,
    00127   INVALID_STRING_ID
    00128 };
    00129
    00130 static const StringID _order_goto_dropdown_aircraft[] = {
    00131   STR_ORDER_GO_TO,
    00132   STR_ORDER_GO_TO_NEAREST_HANGAR,
    00133   STR_ORDER_CONDITIONAL,
    00134   INVALID_STRING_ID
    00135 };
    00136
    00137 static const StringID _order_conditional_variable[] = {
    00138   STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE,
    00139   STR_ORDER_CONDITIONAL_RELIABILITY,
    00140   STR_ORDER_CONDITIONAL_MAX_SPEED,
    00141   STR_ORDER_CONDITIONAL_AGE,
    00142   STR_ORDER_CONDITIONAL_REQUIRES_SERVICE,
    00143   STR_ORDER_CONDITIONAL_UNCONDITIONALLY,
    00144   INVALID_STRING_ID,
    00145 };
    00146
    00147 static const StringID _order_conditional_condition[] = {
    00148   STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
    00149   STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
    00150   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
    00151   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
    00152   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
    00153   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
    00154   STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
    00155   STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
    00156   INVALID_STRING_ID,
    00157 };
    00158
    00159 extern uint ConvertSpeedToDisplaySpeed(uint speed);
    00160 extern uint ConvertDisplaySpeedToSpeed(uint speed);
    00161
    00162 static const StringID _order_depot_action_dropdown[] = {
    00163   STR_ORDER_DROP_GO_ALWAYS_DEPOT,
    00164   STR_ORDER_DROP_SERVICE_DEPOT,
    00165   STR_ORDER_DROP_HALT_DEPOT,
    00166   INVALID_STRING_ID
    00167 };
    00168
    00169 static int DepotActionStringIndex(const Order *order)
    00170 {
    00171   if (order->GetDepotActionType() & ODATFB_HALT) {
    00172     return DA_STOP;
    00173   } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00174     return DA_SERVICE;
    00175   } else {
    00176     return DA_ALWAYS_GO;
    00177   }
    00178 }
    00179
    00192 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
    00193 {
    00194   bool rtl = _dynlang.text_dir == TD_RTL;
    00195
    00196   SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
    00197   Dimension sprite_size = GetSpriteSize(sprite);
    00198   if (v->cur_order_index == order_index) {
    00199     DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00200   }
    00201
    00202   SetDParam(0, order_index + 1);
    00203   DrawString(left, rtl ? right - sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, selected ? TC_WHITE : TC_BLACK, SA_RIGHT | SA_FORCE);
    00204
    00205   SetDParam(5, STR_EMPTY);
    00206
    00207   switch (order->GetType()) {
    00208     case OT_DUMMY:
    00209       SetDParam(0, STR_INVALID_ORDER);
    00210       SetDParam(1, order->GetDestination());
    00211       break;
    00212
    00213     case OT_GOTO_STATION: {
    00214       OrderLoadFlags load = order->GetLoadType();
    00215       OrderUnloadFlags unload = order->GetUnloadType();
    00216
    00217       SetDParam(0, STR_ORDER_GO_TO_STATION);
    00218       SetDParam(1, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0));
    00219       SetDParam(2, order->GetDestination());
    00220
    00221       if (timetable) {
    00222         SetDParam(3, STR_EMPTY);
    00223
    00224         if (order->wait_time > 0) {
    00225           SetDParam(5, STR_TIMETABLE_STAY_FOR);
    00226           SetTimetableParams(6, 7, order->wait_time);
    00227         }
    00228       } else {
    00229         SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]);
    00230         if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
    00231           SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
    00232         }
    00233       }
    00234     } break;
    00235
    00236     case OT_GOTO_DEPOT:
    00237       if (v->type == VEH_AIRCRAFT) {
    00238         if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00239           SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
    00240           SetDParam(2, STR_ORDER_NEAREST_HANGAR);
    00241         } else {
    00242           SetDParam(0, STR_ORDER_GO_TO_HANGAR_FORMAT);
    00243           SetDParam(2, order->GetDestination());
    00244         }
    00245         SetDParam(3, STR_EMPTY);
    00246       } else {
    00247         if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00248           SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
    00249           SetDParam(2, STR_ORDER_NEAREST_DEPOT);
    00250         } else {
    00251           SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
    00252           SetDParam(2, Depot::Get(order->GetDestination())->town_index);
    00253         }
    00254
    00255         SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
    00256       }
    00257
    00258       if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00259         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
    00260       } else {
    00261         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
    00262       }
    00263
    00264       if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
    00265         SetDParam(5, STR_ORDER_STOP_ORDER);
    00266       }
    00267
    00268       if (!timetable && order->IsRefit()) {
    00269         SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
    00270         SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
    00271       }
    00272       break;
    00273
    00274     case OT_GOTO_WAYPOINT:
    00275       SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
    00276       SetDParam(1, order->GetDestination());
    00277       break;
    00278
    00279     case OT_CONDITIONAL:
    00280       SetDParam(1, order->GetConditionSkipToOrder() + 1);
    00281       if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
    00282         SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
    00283       } else {
    00284         OrderConditionComparator occ = order->GetConditionComparator();
    00285         SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
    00286         SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
    00287         SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
    00288
    00289         uint value = order->GetConditionValue();
    00290         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00291         SetDParam(4, value);
    00292       }
    00293
    00294       if (timetable && order->wait_time > 0) {
    00295         SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR);
    00296         SetTimetableParams(6, 7, order->wait_time);
    00297       } else {
    00298         SetDParam(5, STR_EMPTY);
    00299       }
    00300       break;
    00301
    00302     default: NOT_REACHED();
    00303   }
    00304
    00305   DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, selected ? TC_WHITE : TC_BLACK);
    00306 }
    00307
    00308
    00309 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
    00310 {
    00311   Order order;
    00312   order.next  = NULL;
    00313   order.index = 0;
    00314
    00315   /* check depot first */
    00316   if (_settings_game.order.gotodepot) {
    00317     switch (GetTileType(tile)) {
    00318       case MP_RAILWAY:
    00319         if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
    00320           if (IsRailDepot(tile)) {
    00321             order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00322                 _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00323             if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00324             return order;
    00325           }
    00326         }
    00327         break;
    00328
    00329       case MP_ROAD:
    00330         if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
    00331           order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00332               _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00333           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00334           return order;
    00335         }
    00336         break;
    00337
    00338       case MP_STATION:
    00339         if (v->type != VEH_AIRCRAFT) break;
    00340         if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
    00341           order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00342           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00343           return order;
    00344         }
    00345         break;
    00346
    00347       case MP_WATER:
    00348         if (v->type != VEH_SHIP) break;
    00349         if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
    00350           order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00351           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00352           return order;
    00353         }
    00354
    00355       default:
    00356         break;
    00357     }
    00358   }
    00359
    00360   /* check waypoint */
    00361   if (IsRailWaypointTile(tile) &&
    00362       v->type == VEH_TRAIN &&
    00363       IsTileOwner(tile, _local_company)) {
    00364     order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
    00365     if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
    00366     return order;
    00367   }
    00368
    00369   if ((IsBuoyTile(tile) && v->type == VEH_SHIP) || (IsRailWaypointTile(tile) && v->type == VEH_TRAIN)) {
    00370     order.MakeGoToWaypoint(GetStationIndex(tile));
    00371     return order;
    00372   }
    00373
    00374   if (IsTileType(tile, MP_STATION)) {
    00375     StationID st_index = GetStationIndex(tile);
    00376     const Station *st = Station::Get(st_index);
    00377
    00378     if (st->owner == _local_company || st->owner == OWNER_NONE) {
    00379       byte facil;
    00380       (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
    00381       (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
    00382       (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
    00383       (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
    00384       (facil = FACIL_TRUCK_STOP, 1);
    00385       if (st->facilities & facil) {
    00386         order.MakeGoToStation(st_index);
    00387         if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
    00388         if (_settings_client.gui.new_nonstop && (v->type == VEH_TRAIN || v->type == VEH_ROAD)) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00389         order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
    00390         return order;
    00391       }
    00392     }
    00393   }
    00394
    00395   /* not found */
    00396   order.Free();
    00397   return order;
    00398 }
    00399
    00439 struct OrdersWindow : public Window {
    00440 private:
    00442   enum OrderPlaceObjectState {
    00443     OPOS_GOTO,
    00444     OPOS_CONDITIONAL,
    00445   };
    00446
    00448   enum DisplayPane {
    00449     /* ORDER_WIDGET_SEL_TOP_LEFT */
    00450     DP_LEFT_NONSTOP    = 0,
    00451     DP_LEFT_CONDVAR    = 1,
    00452
    00453     /* ORDER_WIDGET_SEL_TOP_MIDDLE */
    00454     DP_MIDDLE_LOAD     = 0,
    00455     DP_MIDDLE_REFIT    = 1,
    00456     DP_MIDDLE_COMPARE  = 2,
    00457
    00458     /* ORDER_WIDGET_SEL_TOP_RIGHT */
    00459     DP_RIGHT_UNLOAD    = 0,
    00460     DP_RIGHT_SERVICE   = 1,
    00461     DP_RIGHT_CONDVAL   = 2,
    00462
    00463     /* ORDER_WIDGET_SEL_TOP_ROW */
    00464     DP_ROW_LOAD        = 0,
    00465     DP_ROW_DEPOT       = 1,
    00466     DP_ROW_CONDITIONAL = 2,
    00467   };
    00468
    00469   int selected_order;
    00470   OrderPlaceObjectState goto_type;
    00471   const Vehicle *vehicle;
    00472
    00478   int OrderGetSel() const
    00479   {
    00480     int num = this->selected_order;
    00481     return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
    00482   }
    00483
    00492   int GetOrderFromPt(int y)
    00493   {
    00494     NWidgetBase *nwid = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST);
    00495     int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the ORDER_WIDGET_ORDER_LIST panel.
    00496
    00497     if ((uint)sel >= this->vscroll.GetCapacity()) return INVALID_ORDER;
    00498
    00499     sel += this->vscroll.GetPosition();
    00500
    00501     return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_ORDER;
    00502   }
    00503
    00504   bool HandleOrderVehClick(const Vehicle *u)
    00505   {
    00506     if (u->type != this->vehicle->type) return false;
    00507
    00508     if (!u->IsPrimaryVehicle()) {
    00509       u = u->First();
    00510       if (!u->IsPrimaryVehicle()) return false;
    00511     }
    00512
    00513     /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
    00514      * obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */
    00515     if (this->vehicle->GetNumOrders() != 0 && _ctrl_pressed == 0) return false;
    00516
    00517     if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY,
    00518       _ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST))) {
    00519       this->selected_order = -1;
    00520       ResetObjectToPlace();
    00521     }
    00522
    00523     return true;
    00524   }
    00525
    00530   void OrderClick_Goto(int i)
    00531   {
    00532     this->SetWidgetDirty(ORDER_WIDGET_GOTO);
    00533     this->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO);
    00534     if (this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    00535       _place_clicked_vehicle = NULL;
    00536       SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT, this);
    00537       this->goto_type = OPOS_GOTO;
    00538     } else {
    00539       ResetObjectToPlace();
    00540     }
    00541   }
    00542
    00547   void OrderClick_FullLoad(int load_type)
    00548   {
    00549     VehicleOrderID sel_ord = this->OrderGetSel();
    00550     const Order *order = this->vehicle->GetOrder(sel_ord);
    00551
    00552     if (order == NULL || order->GetLoadType() == load_type) return;
    00553
    00554     if (load_type < 0) {
    00555       load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
    00556     }
    00557     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 16), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00558   }
    00559
    00563   void OrderClick_Service(int i)
    00564   {
    00565     VehicleOrderID sel_ord = this->OrderGetSel();
    00566
    00567     if (i < 0) {
    00568       const Order *order = this->vehicle->GetOrder(sel_ord);
    00569       if (order == NULL) return;
    00570       i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
    00571     }
    00572     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00573   }
    00574
    00579   void OrderClick_NearestDepot(int i)
    00580   {
    00581     Order order;
    00582     order.next = NULL;
    00583     order.index = 0;
    00584     order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
    00585         _settings_client.gui.new_nonstop && (this->vehicle->type == VEH_TRAIN || this->vehicle->type == VEH_ROAD) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00586     order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
    00587
    00588     DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    00589   }
    00590
    00595   void OrderClick_Conditional(int i)
    00596   {
    00597     this->SetWidgetDirty(ORDER_WIDGET_GOTO);
    00598     this->LowerWidget(ORDER_WIDGET_GOTO);
    00599     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT, this);
    00600     this->goto_type = OPOS_CONDITIONAL;
    00601   }
    00602
    00606   void OrderClick_Unload(int unload_type)
    00607   {
    00608     VehicleOrderID sel_ord = this->OrderGetSel();
    00609     const Order *order = this->vehicle->GetOrder(sel_ord);
    00610
    00611     if (order == NULL || order->GetUnloadType() == unload_type) return;
    00612
    00613     if (unload_type < 0) {
    00614       unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
    00615     }
    00616
    00617     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 16), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00618   }
    00619
    00624   void OrderClick_Nonstop(int non_stop)
    00625   {
    00626     VehicleOrderID sel_ord = this->OrderGetSel();
    00627     const Order *order = this->vehicle->GetOrder(sel_ord);
    00628
    00629     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00630
    00631     /* Keypress if negative, so 'toggle' to the next */
    00632     if (non_stop < 0) {
    00633       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00634     }
    00635
    00636     this->SetWidgetDirty(ORDER_WIDGET_NON_STOP);
    00637     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00638   }
    00639
    00645   void OrderClick_Skip(int i)
    00646   {
    00647     /* Don't skip when there's nothing to skip */
    00648     if (_ctrl_pressed && this->vehicle->cur_order_index == this->OrderGetSel()) return;
    00649     if (this->vehicle->GetNumOrders() <= 1) return;
    00650
    00651     DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_order_index + 1) % this->vehicle->GetNumOrders()),
    00652         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
    00653   }
    00654
    00659   void OrderClick_Delete(int i)
    00660   {
    00661     /* When networking, move one order lower */
    00662     int selected = this->selected_order + (int)_networking;
    00663
    00664     if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
    00665       this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
    00666       this->UpdateButtonState();
    00667     }
    00668   }
    00669
    00675   void OrderClick_Refit(int i)
    00676   {
    00677     if (_ctrl_pressed) {
    00678       /* Cancel refitting */
    00679       DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00680     } else {
    00681       ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this);
    00682     }
    00683   }
    00684   typedef void (OrdersWindow::*Handler)(int);
    00685   struct KeyToEvent {
    00686     uint16 keycode;
    00687     Handler proc;
    00688   };
    00689
    00690 public:
    00691   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window()
    00692   {
    00693     this->vehicle = v;
    00694
    00695     this->InitNested(desc, v->index);
    00696
    00697     this->selected_order = -1;
    00698     this->owner = v->owner;
    00699
    00700     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00701       /* If there are less than 2 station, make Go To active. */
    00702       int station_orders = 0;
    00703       const Order *order;
    00704       FOR_VEHICLE_ORDERS(v, order) {
    00705         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00706       }
    00707
    00708       if (station_orders < 2) this->OrderClick_Goto(0);
    00709     }
    00710     this->OnInvalidateData(-2);
    00711   }
    00712
    00713   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00714   {
    00715     switch (widget) {
    00716       case ORDER_WIDGET_TIMETABLE_VIEW:
    00717         if (!_settings_game.order.timetabling) size->width = 0;
    00718         break;
    00719
    00720       case ORDER_WIDGET_ORDER_LIST:
    00721         resize->height = FONT_HEIGHT_NORMAL;
    00722         size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00723         break;
    00724
    00725       case ORDER_WIDGET_COND_VARIABLE: {
    00726         Dimension d = {0, 0};
    00727         for (int i = 0; _order_conditional_variable[i] != INVALID_STRING_ID; i++) {
    00728           d = maxdim(d, GetStringBoundingBox(_order_conditional_variable[i]));
    00729         }
    00730         d.width += padding.width;
    00731         d.height += padding.height;
    00732         *size = maxdim(*size, d);
    00733         break;
    00734       }
    00735
    00736       case ORDER_WIDGET_COND_COMPARATOR: {
    00737         Dimension d = {0, 0};
    00738         for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
    00739           d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
    00740         }
    00741         d.width += padding.width;
    00742         d.height += padding.height;
    00743         *size = maxdim(*size, d);
    00744         break;
    00745       }
    00746     }
    00747   }
    00748
    00749   virtual void OnInvalidateData(int data)
    00750   {
    00751     switch (data) {
    00752       case 0:
    00753         /* Autoreplace replaced the vehicle */
    00754         this->vehicle = Vehicle::Get(this->window_number);
    00755         break;
    00756
    00757       case -1:
    00758         /* Removed / replaced all orders (after deleting / sharing) */
    00759         if (this->selected_order == -1) break;
    00760
    00761         this->DeleteChildWindows();
    00762         HideDropDownMenu(this);
    00763         this->selected_order = -1;
    00764         break;
    00765
    00766       case -2:
    00767         /* Some other order changes */
    00768         break;
    00769
    00770       default: {
    00771         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00772          * the order is being created / removed */
    00773         if (this->selected_order == -1) break;
    00774
    00775         VehicleOrderID from = GB(data, 0, 8);
    00776         VehicleOrderID to   = GB(data, 8, 8);
    00777
    00778         if (from == to) break; // no need to change anything
    00779
    00780         if (from != this->selected_order) {
    00781           /* Moving from preceeding order? */
    00782           this->selected_order -= (int)(from <= this->selected_order);
    00783           /* Moving to   preceeding order? */
    00784           this->selected_order += (int)(to   <= this->selected_order);
    00785           break;
    00786         }
    00787
    00788         /* Now we are modifying the selected order */
    00789         if (to == INVALID_VEH_ORDER_ID) {
    00790           /* Deleting selected order */
    00791           this->DeleteChildWindows();
    00792           HideDropDownMenu(this);
    00793           this->selected_order = -1;
    00794           break;
    00795         }
    00796
    00797         /* Moving selected order */
    00798         this->selected_order = to;
    00799       } break;
    00800     }
    00801
    00802     this->vscroll.SetCount(this->vehicle->GetNumOrders() + 1);
    00803     this->UpdateButtonState();
    00804   }
    00805
    00806   void UpdateButtonState()
    00807   {
    00808     if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
    00809
    00810     bool shared_orders = this->vehicle->IsOrderListShared();
    00811     int sel = this->OrderGetSel();
    00812     const Order *order = this->vehicle->GetOrder(sel);
    00813
    00814     /* Second row. */
    00815     /* skip */
    00816     this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1);
    00817
    00818     /* delete */
    00819     this->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
    00820         (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00821
    00822     /* First row. */
    00823     this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
    00824     this->RaiseWidget(ORDER_WIDGET_UNLOAD);
    00825     this->RaiseWidget(ORDER_WIDGET_SERVICE);
    00826
    00827     /* Selection widgets. */
    00828     /* Train or road vehicle. */
    00829     NWidgetStacked *left_sel   = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_LEFT);
    00830     NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_MIDDLE);
    00831     NWidgetStacked *right_sel  = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_RIGHT);
    00832     /* Ship or airplane. */
    00833     NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_ROW);
    00834     assert(row_sel != NULL || (left_sel != NULL && middle_sel != NULL && right_sel != NULL));
    00835
    00836
    00837     if (order == NULL) {
    00838       if (row_sel != NULL) {
    00839         row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00840       } else {
    00841         left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00842         middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00843         right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00844         this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00845         this->RaiseWidget(ORDER_WIDGET_NON_STOP);
    00846       }
    00847       this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00848       this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00849     } else {
    00850       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    00851       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    00852
    00853       switch (order->GetType()) {
    00854         case OT_GOTO_STATION:
    00855           if (row_sel != NULL) {
    00856             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00857           } else {
    00858             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00859             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00860             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00861             this->EnableWidget(ORDER_WIDGET_NON_STOP);
    00862             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00863           }
    00864           this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    00865           this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    00866           break;
    00867
    00868         case OT_GOTO_WAYPOINT:
    00869           if (row_sel != NULL) {
    00870             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00871           } else {
    00872             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00873             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00874             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00875             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00876           }
    00877           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00878           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00879           break;
    00880
    00881         case OT_GOTO_DEPOT:
    00882           if (row_sel != NULL) {
    00883             row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
    00884           } else {
    00885             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00886             middle_sel->SetDisplayedPlane(DP_MIDDLE_REFIT);
    00887             right_sel->SetDisplayedPlane(DP_RIGHT_SERVICE);
    00888             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00889           }
    00890           this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    00891           break;
    00892
    00893         case OT_CONDITIONAL: {
    00894           if (row_sel != NULL) {
    00895             row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
    00896           } else {
    00897             left_sel->SetDisplayedPlane(DP_LEFT_CONDVAR);
    00898             middle_sel->SetDisplayedPlane(DP_MIDDLE_COMPARE);
    00899             right_sel->SetDisplayedPlane(DP_RIGHT_CONDVAL);
    00900           }
    00901           OrderConditionVariable ocv = order->GetConditionVariable();
    00902           /* Set the strings for the dropdown boxes. */
    00903           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_VARIABLE)->widget_data   = _order_conditional_variable[order == NULL ? 0 : ocv];
    00904           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    00905           this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    00906           this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    00907           break;
    00908         }
    00909
    00910         default: // every other order
    00911           if (row_sel != NULL) {
    00912             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00913           } else {
    00914             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00915             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00916             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00917             this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00918           }
    00919           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00920           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00921           break;
    00922       }
    00923     }
    00924
    00925     /* Disable list of vehicles with the same shared orders if there is no list */
    00926     this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
    00927
    00928     this->SetDirty();
    00929   }
    00930
    00931   virtual void OnPaint()
    00932   {
    00933     if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window.
    00934     this->DrawWidgets();
    00935   }
    00936
    00937   virtual void DrawWidget(const Rect &r, int widget) const
    00938   {
    00939     if (widget != ORDER_WIDGET_ORDER_LIST) return;
    00940
    00941     bool rtl = _dynlang.text_dir == TD_RTL;
    00942     SetDParam(0, 99);
    00943     int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
    00944     int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
    00945
    00946     int y = r.top + WD_FRAMERECT_TOP;
    00947     int line_height = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST)->resize_y;
    00948
    00949     int i = this->vscroll.GetPosition();
    00950     const Order *order = this->vehicle->GetOrder(i);
    00951     StringID str;
    00952     while (order != NULL) {
    00953       /* Don't draw anything if it extends past the end of the window. */
    00954       if (!this->vscroll.IsVisible(i)) break;
    00955
    00956       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
    00957       y += line_height;
    00958
    00959       i++;
    00960       order = order->next;
    00961     }
    00962
    00963     if (this->vscroll.IsVisible(i)) {
    00964       str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
    00965       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);
    00966     }
    00967   }
    00968
    00969   virtual void SetStringParameters(int widget) const
    00970   {
    00971     switch (widget) {
    00972       case ORDER_WIDGET_COND_VALUE: {
    00973         int sel = this->OrderGetSel();
    00974         const Order *order = this->vehicle->GetOrder(sel);
    00975
    00976         if (order != NULL && order->IsType(OT_CONDITIONAL)) {
    00977           uint value = order->GetConditionValue();
    00978           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00979           SetDParam(0, value);
    00980         }
    00981         break;
    00982       }
    00983
    00984       case ORDER_WIDGET_CAPTION:
    00985         SetDParam(0, this->vehicle->index);
    00986         break;
    00987     }
    00988   }
    00989
    00990   virtual void OnClick(Point pt, int widget)
    00991   {
    00992     switch (widget) {
    00993       case ORDER_WIDGET_ORDER_LIST: {
    00994         ResetObjectToPlace();
    00995
    00996         int sel = this->GetOrderFromPt(pt.y);
    00997
    00998         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    00999           const Order *ord = this->vehicle->GetOrder(sel);
    01000           TileIndex xy = INVALID_TILE;
    01001
    01002           switch (ord->GetType()) {
    01003             case OT_GOTO_WAYPOINT:
    01004               if (this->vehicle->type == VEH_TRAIN) {
    01005                 xy = Waypoint::Get(ord->GetDestination())->xy;
    01006                 break;
    01007               }
    01008               /* FALL THROUGH */
    01009             case OT_GOTO_STATION:
    01010               xy = Station::Get(ord->GetDestination())->xy;
    01011               break;
    01012
    01013             case OT_GOTO_DEPOT:
    01014               if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
    01015               xy = (this->vehicle->type == VEH_AIRCRAFT) ?  Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy;
    01016               break;
    01017             default:
    01018               break;
    01019           }
    01020
    01021           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    01022           return;
    01023         }
    01024
    01025         /* This order won't be selected any more, close all child windows and dropdowns */
    01026         this->DeleteChildWindows();
    01027         HideDropDownMenu(this);
    01028
    01029         if (sel == INVALID_ORDER || this->vehicle->owner != _local_company) {
    01030           /* Deselect clicked order */
    01031           this->selected_order = -1;
    01032         } else if (sel == this->selected_order) {
    01033           if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
    01034             DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
    01035                 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
    01036                 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01037           }
    01038         } else {
    01039           /* Select clicked order */
    01040           this->selected_order = sel;
    01041
    01042           if (this->vehicle->owner == _local_company) {
    01043             /* Activate drag and drop */
    01044             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
    01045           }
    01046         }
    01047
    01048         this->UpdateButtonState();
    01049       } break;
    01050
    01051       case ORDER_WIDGET_SKIP:
    01052         this->OrderClick_Skip(0);
    01053         break;
    01054
    01055       case ORDER_WIDGET_DELETE:
    01056         this->OrderClick_Delete(0);
    01057         break;
    01058
    01059       case ORDER_WIDGET_NON_STOP:
    01060         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01061           this->OrderClick_Nonstop(-1);
    01062         } else {
    01063           const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01064           ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP, 0,
    01065                           o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
    01066         }
    01067         break;
    01068
    01069       case ORDER_WIDGET_GOTO:
    01070         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01071           this->OrderClick_Goto(0);
    01072         } else {
    01073           ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO, 0, 0);
    01074         }
    01075         break;
    01076
    01077       case ORDER_WIDGET_FULL_LOAD:
    01078         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01079           this->OrderClick_FullLoad(-1);
    01080         } else {
    01081           ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD, 0, 2);
    01082         }
    01083         break;
    01084
    01085       case ORDER_WIDGET_UNLOAD:
    01086         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01087           this->OrderClick_Unload(-1);
    01088         } else {
    01089           ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD, 0, 8);
    01090         }
    01091         break;
    01092
    01093       case ORDER_WIDGET_REFIT:
    01094         this->OrderClick_Refit(0);
    01095         break;
    01096
    01097       case ORDER_WIDGET_SERVICE:
    01098         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01099           this->OrderClick_Service(-1);
    01100         } else {
    01101           ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE, 0, 0);
    01102         }
    01103         break;
    01104
    01105       case ORDER_WIDGET_TIMETABLE_VIEW:
    01106         ShowTimetableWindow(this->vehicle);
    01107         break;
    01108
    01109       case ORDER_WIDGET_COND_VARIABLE:
    01110         ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
    01111         break;
    01112
    01113       case ORDER_WIDGET_COND_COMPARATOR: {
    01114         const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01115         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    01116       } break;
    01117
    01118       case ORDER_WIDGET_COND_VALUE: {
    01119         const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
    01120         uint value = order->GetConditionValue();
    01121         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01122         SetDParam(0, value);
    01123         ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
    01124       } break;
    01125
    01126       case ORDER_WIDGET_SHARED_ORDER_LIST:
    01127         ShowVehicleListWindow(this->vehicle);
    01128         break;
    01129     }
    01130   }
    01131
    01132   virtual void OnQueryTextFinished(char *str)
    01133   {
    01134     if (!StrEmpty(str)) {
    01135       VehicleOrderID sel = this->OrderGetSel();
    01136       uint value = atoi(str);
    01137
    01138       switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
    01139         case OCV_MAX_SPEED:
    01140           value = ConvertDisplaySpeedToSpeed(value);
    01141           break;
    01142
    01143         case OCV_RELIABILITY:
    01144         case OCV_LOAD_PERCENTAGE:
    01145           value = Clamp(value, 0, 100);
    01146
    01147         default:
    01148           break;
    01149       }
    01150       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01151     }
    01152   }
    01153
    01154   virtual void OnDropdownSelect(int widget, int index)
    01155   {
    01156     switch (widget) {
    01157       case ORDER_WIDGET_NON_STOP:
    01158         this->OrderClick_Nonstop(index);
    01159         break;
    01160
    01161       case ORDER_WIDGET_FULL_LOAD:
    01162         this->OrderClick_FullLoad(index);
    01163         break;
    01164
    01165       case ORDER_WIDGET_UNLOAD:
    01166         this->OrderClick_Unload(index);
    01167         break;
    01168
    01169       case ORDER_WIDGET_GOTO:
    01170         switch (index) {
    01171           case 0: this->OrderClick_Goto(0); break;
    01172           case 1: this->OrderClick_NearestDepot(0); break;
    01173           case 2: this->OrderClick_Conditional(0); break;
    01174           default: NOT_REACHED();
    01175         }
    01176         break;
    01177
    01178       case ORDER_WIDGET_SERVICE:
    01179         this->OrderClick_Service(index);
    01180         break;
    01181
    01182       case ORDER_WIDGET_COND_VARIABLE:
    01183         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01184         break;
    01185
    01186       case ORDER_WIDGET_COND_COMPARATOR:
    01187         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_COMPARATOR | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01188         break;
    01189     }
    01190   }
    01191
    01192   virtual void OnDragDrop(Point pt, int widget)
    01193   {
    01194     switch (widget) {
    01195       case ORDER_WIDGET_ORDER_LIST: {
    01196         int from_order = this->OrderGetSel();
    01197         int to_order = this->GetOrderFromPt(pt.y);
    01198
    01199         if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
    01200             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
    01201           this->selected_order = -1;
    01202           this->UpdateButtonState();
    01203         }
    01204       } break;
    01205
    01206       case ORDER_WIDGET_DELETE:
    01207         this->OrderClick_Delete(0);
    01208         break;
    01209     }
    01210
    01211     ResetObjectToPlace();
    01212   }
    01213
    01214   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01215   {
    01216     static const KeyToEvent keytoevent[] = {
    01217       {'D', &OrdersWindow::OrderClick_Skip},
    01218       {'F', &OrdersWindow::OrderClick_Delete},
    01219       {'G', &OrdersWindow::OrderClick_Goto},
    01220       {'H', &OrdersWindow::OrderClick_Nonstop},
    01221       {'J', &OrdersWindow::OrderClick_FullLoad},
    01222       {'K', &OrdersWindow::OrderClick_Unload},
    01223       //('?', &OrdersWindow::OrderClick_Service},
    01224     };
    01225
    01226     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01227
    01228     for (uint i = 0; i < lengthof(keytoevent); i++) {
    01229       if (keycode == keytoevent[i].keycode) {
    01230         (this->*(keytoevent[i].proc))(-1);
    01231         return ES_HANDLED;
    01232       }
    01233     }
    01234     return ES_NOT_HANDLED;
    01235   }
    01236
    01237   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01238   {
    01239     if (this->goto_type == OPOS_GOTO) {
    01240       /* check if we're clicking on a vehicle first.. clone orders in that case. */
    01241       const Vehicle *v = CheckMouseOverVehicle();
    01242       if (v != NULL && this->HandleOrderVehClick(v)) return;
    01243
    01244       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01245       if (cmd.IsType(OT_NOTHING)) return;
    01246
    01247       if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
    01248         /* With quick goto the Go To button stays active */
    01249         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01250       }
    01251     }
    01252   }
    01253
    01254   virtual void OnPlaceObjectAbort()
    01255   {
    01256     if (this->goto_type == OPOS_CONDITIONAL) {
    01257       this->goto_type = OPOS_GOTO;
    01258       NWidgetBase *nwid = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST);
    01259       if (IsInsideBS(_cursor.pos.x, this->left + nwid->pos_x, nwid->current_x) && IsInsideBS(_cursor.pos.y, this->top + nwid->pos_y, nwid->current_y)) {
    01260         int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01261         if (order_id != INVALID_ORDER) {
    01262           Order order;
    01263           order.next = NULL;
    01264           order.index = 0;
    01265           order.MakeConditional(order_id);
    01266
    01267           DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    01268         }
    01269       }
    01270     }
    01271     this->RaiseWidget(ORDER_WIDGET_GOTO);
    01272     this->SetWidgetDirty(ORDER_WIDGET_GOTO);
    01273   }
    01274
    01275   virtual void OnMouseLoop()
    01276   {
    01277     const Vehicle *v = _place_clicked_vehicle;
    01278     /*
    01279      * Check if we clicked on a vehicle
    01280      * and if the GOTO button of this window is pressed
    01281      * This is because of all open order windows WE_MOUSELOOP is called
    01282      * and if you have 3 windows open, and this check is not done
    01283      * the order is copied to the last open window instead of the
    01284      * one where GOTO is enabled
    01285      */
    01286     if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    01287       _place_clicked_vehicle = NULL;
    01288       this->HandleOrderVehClick(v);
    01289     }
    01290   }
    01291
    01292   virtual void OnResize()
    01293   {
    01294     /* Update the scroll bar */
    01295     this->vscroll.SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
    01296   }
    01297
    01298   virtual void OnTimeout()
    01299   {
    01300     /* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
    01301     for (uint i = 0; i < this->nested_array_size; i++) {
    01302       if (this->nested_array[i] != NULL && i != ORDER_WIDGET_GOTO &&
    01303           i != ORDER_WIDGET_SEL_TOP_LEFT && i != ORDER_WIDGET_SEL_TOP_MIDDLE && i != ORDER_WIDGET_SEL_TOP_RIGHT &&
    01304           i != ORDER_WIDGET_SEL_TOP_ROW && this->IsWidgetLowered(i)) {
    01305         this->RaiseWidget(i);
    01306         this->SetWidgetDirty(i);
    01307       }
    01308     }
    01309   }
    01310 };
    01311
    01313 static const NWidgetPart _nested_orders_train_widgets[] = {
    01314   NWidget(NWID_HORIZONTAL),
    01315     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01316     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01317     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01318     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01319     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01320   EndContainer(),
    01321   NWidget(NWID_HORIZONTAL),
    01322     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01323     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01324   EndContainer(),
    01325
    01326   /* First button row. */
    01327   NWidget(NWID_HORIZONTAL),
    01328     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01329       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_LEFT),
    01330         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_NON_STOP), SetMinimalSize(124, 12), SetFill(1, 0),
    01331                             SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
    01332         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01333                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01334       EndContainer(),
    01335       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_MIDDLE),
    01336         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01337                             SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01338         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(124, 12), SetFill(1, 0),
    01339                             SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01340         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01341                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01342       EndContainer(),
    01343       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_RIGHT),
    01344         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01345                             SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01346         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01347                             SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01348         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01349                             SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01350       EndContainer(),
    01351     EndContainer(),
    01352     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, ORDER_WIDGET_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01353   EndContainer(),
    01354
    01355   /* Second button row. */
    01356   NWidget(NWID_HORIZONTAL),
    01357     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01358       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01359                           SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01360       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01361                           SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01362       NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01363                           SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01364     EndContainer(),
    01365     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01366   EndContainer(),
    01367 };
    01368
    01369 static const WindowDesc _orders_train_desc(
    01370   WDP_AUTO, 384, 100,
    01371   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01372   0,
    01373   _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets)
    01374 );
    01375
    01377 static const NWidgetPart _nested_orders_widgets[] = {
    01378   NWidget(NWID_HORIZONTAL),
    01379     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01380     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01381     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01382     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01383     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01384   EndContainer(),
    01385   NWidget(NWID_HORIZONTAL),
    01386     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01387     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01388   EndContainer(),
    01389
    01390   /* First button row. */
    01391   NWidget(NWID_HORIZONTAL),
    01392     NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_ROW),
    01393       /* load + unload buttons. */
    01394       NWidget(NWID_HORIZONTAL),
    01395         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01396                           SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01397         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01398                           SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01399       EndContainer(),
    01400       /* Refit + service buttons. */
    01401       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01402         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
    01403                           SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01404         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01405                           SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01406       EndContainer(),
    01407
    01408       /* Buttons for setting a condition. */
    01409       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01410         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01411                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01412         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01413                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01414         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01415                           SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01416       EndContainer(),
    01417     EndContainer(),
    01418
    01419     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, ORDER_WIDGET_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01420   EndContainer(),
    01421
    01422   /* Second button row. */
    01423   NWidget(NWID_HORIZONTAL),
    01424     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01425                       SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01426     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01427                       SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01428     NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01429                       SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01430     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01431   EndContainer(),
    01432 };
    01433
    01434 static const WindowDesc _orders_desc(
    01435   WDP_AUTO, 384, 100,
    01436   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01437   0,
    01438   _nested_orders_widgets, lengthof(_nested_orders_widgets)
    01439 );
    01440
    01442 static const NWidgetPart _nested_other_orders_widgets[] = {
    01443   NWidget(NWID_HORIZONTAL),
    01444     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01445     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01446     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01447     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01448     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01449   EndContainer(),
    01450   NWidget(NWID_HORIZONTAL),
    01451     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01452     NWidget(NWID_VERTICAL),
    01453       NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01454       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01455     EndContainer(),
    01456   EndContainer(),
    01457 };
    01458
    01459 static const WindowDesc _other_orders_desc(
    01460   WDP_AUTO, 384, 86,
    01461   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01462   WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
    01463   _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets)
    01464 );
    01465
    01466 void ShowOrdersWindow(const Vehicle *v)
    01467 {
    01468   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01469   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01470   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01471
    01472   if (v->owner != _local_company) {
    01473     new OrdersWindow(&_other_orders_desc, v);
    01474   } else {
    01475     new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
    01476   }
    01477 }