# order_gui.cpp

Go to the documentation of this file.

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