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