# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 18980 2010-02-01 12:43:28Z 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->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00874           }
    00875           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00876           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00877           break;
    00878
    00879         case OT_GOTO_DEPOT:
    00880           if (row_sel != NULL) {
    00881             row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
    00882           } else {
    00883             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00884             middle_sel->SetDisplayedPlane(DP_MIDDLE_REFIT);
    00885             right_sel->SetDisplayedPlane(DP_RIGHT_SERVICE);
    00886             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00887           }
    00888           this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    00889           break;
    00890
    00891         case OT_CONDITIONAL: {
    00892           if (row_sel != NULL) {
    00893             row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
    00894           } else {
    00895             left_sel->SetDisplayedPlane(DP_LEFT_CONDVAR);
    00896             middle_sel->SetDisplayedPlane(DP_MIDDLE_COMPARE);
    00897             right_sel->SetDisplayedPlane(DP_RIGHT_CONDVAL);
    00898           }
    00899           OrderConditionVariable ocv = order->GetConditionVariable();
    00900           /* Set the strings for the dropdown boxes. */
    00901           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_VARIABLE)->widget_data   = _order_conditional_variable[order == NULL ? 0 : ocv];
    00902           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    00903           this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    00904           this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    00905           break;
    00906         }
    00907
    00908         default: // every other order
    00909           if (row_sel != NULL) {
    00910             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00911           } else {
    00912             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00913             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00914             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00915             this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00916           }
    00917           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00918           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00919           break;
    00920       }
    00921     }
    00922
    00923     /* Disable list of vehicles with the same shared orders if there is no list */
    00924     this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
    00925
    00926     this->SetDirty();
    00927   }
    00928
    00929   virtual void OnPaint()
    00930   {
    00931     if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window.
    00932     this->DrawWidgets();
    00933   }
    00934
    00935   virtual void DrawWidget(const Rect &r, int widget) const
    00936   {
    00937     if (widget != ORDER_WIDGET_ORDER_LIST) return;
    00938
    00939     bool rtl = _dynlang.text_dir == TD_RTL;
    00940     SetDParam(0, 99);
    00941     int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
    00942     int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
    00943
    00944     int y = r.top + WD_FRAMERECT_TOP;
    00945     int line_height = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST)->resize_y;
    00946
    00947     int i = this->vscroll.GetPosition();
    00948     const Order *order = this->vehicle->GetOrder(i);
    00949     StringID str;
    00950     while (order != NULL) {
    00951       /* Don't draw anything if it extends past the end of the window. */
    00952       if (!this->vscroll.IsVisible(i)) break;
    00953
    00954       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
    00955       y += line_height;
    00956
    00957       i++;
    00958       order = order->next;
    00959     }
    00960
    00961     if (this->vscroll.IsVisible(i)) {
    00962       str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
    00963       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);
    00964     }
    00965   }
    00966
    00967   virtual void SetStringParameters(int widget) const
    00968   {
    00969     switch (widget) {
    00970       case ORDER_WIDGET_COND_VALUE: {
    00971         int sel = this->OrderGetSel();
    00972         const Order *order = this->vehicle->GetOrder(sel);
    00973
    00974         if (order != NULL && order->IsType(OT_CONDITIONAL)) {
    00975           uint value = order->GetConditionValue();
    00976           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00977           SetDParam(0, value);
    00978         }
    00979         break;
    00980       }
    00981
    00982       case ORDER_WIDGET_CAPTION:
    00983         SetDParam(0, this->vehicle->index);
    00984         break;
    00985     }
    00986   }
    00987
    00988   virtual void OnClick(Point pt, int widget, int click_count)
    00989   {
    00990     switch (widget) {
    00991       case ORDER_WIDGET_ORDER_LIST: {
    00992         ResetObjectToPlace();
    00993
    00994         int sel = this->GetOrderFromPt(pt.y);
    00995
    00996         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    00997           const Order *ord = this->vehicle->GetOrder(sel);
    00998           TileIndex xy = INVALID_TILE;
    00999
    01000           switch (ord->GetType()) {
    01001             case OT_GOTO_WAYPOINT:
    01002               if (this->vehicle->type == VEH_TRAIN) {
    01003                 xy = Waypoint::Get(ord->GetDestination())->xy;
    01004                 break;
    01005               }
    01006               /* FALL THROUGH */
    01007             case OT_GOTO_STATION:
    01008               xy = Station::Get(ord->GetDestination())->xy;
    01009               break;
    01010
    01011             case OT_GOTO_DEPOT:
    01012               if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
    01013               xy = (this->vehicle->type == VEH_AIRCRAFT) ?  Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy;
    01014               break;
    01015             default:
    01016               break;
    01017           }
    01018
    01019           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    01020           return;
    01021         }
    01022
    01023         /* This order won't be selected any more, close all child windows and dropdowns */
    01024         this->DeleteChildWindows();
    01025         HideDropDownMenu(this);
    01026
    01027         if (sel == INVALID_ORDER || this->vehicle->owner != _local_company) {
    01028           /* Deselect clicked order */
    01029           this->selected_order = -1;
    01030         } else if (sel == this->selected_order) {
    01031           if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
    01032             DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
    01033                 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
    01034                 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01035           }
    01036         } else {
    01037           /* Select clicked order */
    01038           this->selected_order = sel;
    01039
    01040           if (this->vehicle->owner == _local_company) {
    01041             /* Activate drag and drop */
    01042             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
    01043           }
    01044         }
    01045
    01046         this->UpdateButtonState();
    01047       } break;
    01048
    01049       case ORDER_WIDGET_SKIP:
    01050         this->OrderClick_Skip(0);
    01051         break;
    01052
    01053       case ORDER_WIDGET_DELETE:
    01054         this->OrderClick_Delete(0);
    01055         break;
    01056
    01057       case ORDER_WIDGET_NON_STOP:
    01058         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01059           this->OrderClick_Nonstop(-1);
    01060         } else {
    01061           const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01062           ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP, 0,
    01063                           o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
    01064         }
    01065         break;
    01066
    01067       case ORDER_WIDGET_GOTO:
    01068         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01069           this->OrderClick_Goto(0);
    01070         } else {
    01071           ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO, 0, 0);
    01072         }
    01073         break;
    01074
    01075       case ORDER_WIDGET_FULL_LOAD:
    01076         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01077           this->OrderClick_FullLoad(-1);
    01078         } else {
    01079           ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD, 0, 2);
    01080         }
    01081         break;
    01082
    01083       case ORDER_WIDGET_UNLOAD:
    01084         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01085           this->OrderClick_Unload(-1);
    01086         } else {
    01087           ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD, 0, 8);
    01088         }
    01089         break;
    01090
    01091       case ORDER_WIDGET_REFIT:
    01092         this->OrderClick_Refit(0);
    01093         break;
    01094
    01095       case ORDER_WIDGET_SERVICE:
    01096         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01097           this->OrderClick_Service(-1);
    01098         } else {
    01099           ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE, 0, 0);
    01100         }
    01101         break;
    01102
    01103       case ORDER_WIDGET_TIMETABLE_VIEW:
    01104         ShowTimetableWindow(this->vehicle);
    01105         break;
    01106
    01107       case ORDER_WIDGET_COND_VARIABLE:
    01108         ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
    01109         break;
    01110
    01111       case ORDER_WIDGET_COND_COMPARATOR: {
    01112         const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01113         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    01114       } break;
    01115
    01116       case ORDER_WIDGET_COND_VALUE: {
    01117         const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
    01118         uint value = order->GetConditionValue();
    01119         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01120         SetDParam(0, value);
    01121         ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
    01122       } break;
    01123
    01124       case ORDER_WIDGET_SHARED_ORDER_LIST:
    01125         ShowVehicleListWindow(this->vehicle);
    01126         break;
    01127     }
    01128   }
    01129
    01130   virtual void OnQueryTextFinished(char *str)
    01131   {
    01132     if (!StrEmpty(str)) {
    01133       VehicleOrderID sel = this->OrderGetSel();
    01134       uint value = atoi(str);
    01135
    01136       switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
    01137         case OCV_MAX_SPEED:
    01138           value = ConvertDisplaySpeedToSpeed(value);
    01139           break;
    01140
    01141         case OCV_RELIABILITY:
    01142         case OCV_LOAD_PERCENTAGE:
    01143           value = Clamp(value, 0, 100);
    01144
    01145         default:
    01146           break;
    01147       }
    01148       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));
    01149     }
    01150   }
    01151
    01152   virtual void OnDropdownSelect(int widget, int index)
    01153   {
    01154     switch (widget) {
    01155       case ORDER_WIDGET_NON_STOP:
    01156         this->OrderClick_Nonstop(index);
    01157         break;
    01158
    01159       case ORDER_WIDGET_FULL_LOAD:
    01160         this->OrderClick_FullLoad(index);
    01161         break;
    01162
    01163       case ORDER_WIDGET_UNLOAD:
    01164         this->OrderClick_Unload(index);
    01165         break;
    01166
    01167       case ORDER_WIDGET_GOTO:
    01168         switch (index) {
    01169           case 0: this->OrderClick_Goto(0); break;
    01170           case 1: this->OrderClick_NearestDepot(0); break;
    01171           case 2: this->OrderClick_Conditional(0); break;
    01172           default: NOT_REACHED();
    01173         }
    01174         break;
    01175
    01176       case ORDER_WIDGET_SERVICE:
    01177         this->OrderClick_Service(index);
    01178         break;
    01179
    01180       case ORDER_WIDGET_COND_VARIABLE:
    01181         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));
    01182         break;
    01183
    01184       case ORDER_WIDGET_COND_COMPARATOR:
    01185         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));
    01186         break;
    01187     }
    01188   }
    01189
    01190   virtual void OnDragDrop(Point pt, int widget)
    01191   {
    01192     switch (widget) {
    01193       case ORDER_WIDGET_ORDER_LIST: {
    01194         int from_order = this->OrderGetSel();
    01195         int to_order = this->GetOrderFromPt(pt.y);
    01196
    01197         if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
    01198             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
    01199           this->selected_order = -1;
    01200           this->UpdateButtonState();
    01201         }
    01202       } break;
    01203
    01204       case ORDER_WIDGET_DELETE:
    01205         this->OrderClick_Delete(0);
    01206         break;
    01207     }
    01208
    01209     ResetObjectToPlace();
    01210   }
    01211
    01212   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01213   {
    01214     static const KeyToEvent keytoevent[] = {
    01215       {'D', &OrdersWindow::OrderClick_Skip},
    01216       {'F', &OrdersWindow::OrderClick_Delete},
    01217       {'G', &OrdersWindow::OrderClick_Goto},
    01218       {'H', &OrdersWindow::OrderClick_Nonstop},
    01219       {'J', &OrdersWindow::OrderClick_FullLoad},
    01220       {'K', &OrdersWindow::OrderClick_Unload},
    01221       //('?', &OrdersWindow::OrderClick_Service},
    01222     };
    01223
    01224     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01225
    01226     for (uint i = 0; i < lengthof(keytoevent); i++) {
    01227       if (keycode == keytoevent[i].keycode) {
    01228         (this->*(keytoevent[i].proc))(-1);
    01229         return ES_HANDLED;
    01230       }
    01231     }
    01232     return ES_NOT_HANDLED;
    01233   }
    01234
    01235   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01236   {
    01237     if (this->goto_type == OPOS_GOTO) {
    01238       /* check if we're clicking on a vehicle first.. clone orders in that case. */
    01239       const Vehicle *v = CheckMouseOverVehicle();
    01240       if (v != NULL && this->HandleOrderVehClick(v)) return;
    01241
    01242       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01243       if (cmd.IsType(OT_NOTHING)) return;
    01244
    01245       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))) {
    01246         /* With quick goto the Go To button stays active */
    01247         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01248       }
    01249     }
    01250   }
    01251
    01252   virtual void OnPlaceObjectAbort()
    01253   {
    01254     if (this->goto_type == OPOS_CONDITIONAL) {
    01255       this->goto_type = OPOS_GOTO;
    01256       NWidgetBase *nwid = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST);
    01257       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)) {
    01258         int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01259         if (order_id != INVALID_ORDER) {
    01260           Order order;
    01261           order.next = NULL;
    01262           order.index = 0;
    01263           order.MakeConditional(order_id);
    01264
    01265           DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    01266         }
    01267       }
    01268     }
    01269     this->RaiseWidget(ORDER_WIDGET_GOTO);
    01270     this->SetWidgetDirty(ORDER_WIDGET_GOTO);
    01271   }
    01272
    01273   virtual void OnMouseLoop()
    01274   {
    01275     const Vehicle *v = _place_clicked_vehicle;
    01276     /*
    01277      * Check if we clicked on a vehicle
    01278      * and if the GOTO button of this window is pressed
    01279      * This is because of all open order windows WE_MOUSELOOP is called
    01280      * and if you have 3 windows open, and this check is not done
    01281      * the order is copied to the last open window instead of the
    01282      * one where GOTO is enabled
    01283      */
    01284     if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    01285       _place_clicked_vehicle = NULL;
    01286       this->HandleOrderVehClick(v);
    01287     }
    01288   }
    01289
    01290   virtual void OnResize()
    01291   {
    01292     /* Update the scroll bar */
    01293     this->vscroll.SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
    01294   }
    01295
    01296   virtual void OnTimeout()
    01297   {
    01298     /* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
    01299     for (uint i = 0; i < this->nested_array_size; i++) {
    01300       if (this->nested_array[i] != NULL && i != ORDER_WIDGET_GOTO &&
    01301           i != ORDER_WIDGET_SEL_TOP_LEFT && i != ORDER_WIDGET_SEL_TOP_MIDDLE && i != ORDER_WIDGET_SEL_TOP_RIGHT &&
    01302           i != ORDER_WIDGET_SEL_TOP_ROW && this->IsWidgetLowered(i)) {
    01303         this->RaiseWidget(i);
    01304         this->SetWidgetDirty(i);
    01305       }
    01306     }
    01307   }
    01308 };
    01309
    01311 static const NWidgetPart _nested_orders_train_widgets[] = {
    01312   NWidget(NWID_HORIZONTAL),
    01313     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01314     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01315     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01316     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01317     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01318   EndContainer(),
    01319   NWidget(NWID_HORIZONTAL),
    01320     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01321     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01322   EndContainer(),
    01323
    01324   /* First button row. */
    01325   NWidget(NWID_HORIZONTAL),
    01326     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01327       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_LEFT),
    01328         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_NON_STOP), SetMinimalSize(124, 12), SetFill(1, 0),
    01329                             SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
    01330         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01331                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01332       EndContainer(),
    01333       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_MIDDLE),
    01334         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01335                             SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01336         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(124, 12), SetFill(1, 0),
    01337                             SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01338         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01339                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01340       EndContainer(),
    01341       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_RIGHT),
    01342         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01343                             SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01344         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01345                             SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01346         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01347                             SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01348       EndContainer(),
    01349     EndContainer(),
    01350     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),
    01351   EndContainer(),
    01352
    01353   /* Second button row. */
    01354   NWidget(NWID_HORIZONTAL),
    01355     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01356       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01357                           SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01358       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01359                           SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01360       NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01361                           SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01362     EndContainer(),
    01363     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01364   EndContainer(),
    01365 };
    01366
    01367 static const WindowDesc _orders_train_desc(
    01368   WDP_AUTO, 384, 100,
    01369   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01370   0,
    01371   _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets)
    01372 );
    01373
    01375 static const NWidgetPart _nested_orders_widgets[] = {
    01376   NWidget(NWID_HORIZONTAL),
    01377     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01378     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01379     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01380     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01381     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01382   EndContainer(),
    01383   NWidget(NWID_HORIZONTAL),
    01384     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01385     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01386   EndContainer(),
    01387
    01388   /* First button row. */
    01389   NWidget(NWID_HORIZONTAL),
    01390     NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_ROW),
    01391       /* load + unload buttons. */
    01392       NWidget(NWID_HORIZONTAL),
    01393         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01394                           SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01395         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01396                           SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01397       EndContainer(),
    01398       /* Refit + service buttons. */
    01399       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01400         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
    01401                           SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01402         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01403                           SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01404       EndContainer(),
    01405
    01406       /* Buttons for setting a condition. */
    01407       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01408         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01409                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01410         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01411                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01412         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01413                           SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01414       EndContainer(),
    01415     EndContainer(),
    01416
    01417     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),
    01418   EndContainer(),
    01419
    01420   /* Second button row. */
    01421   NWidget(NWID_HORIZONTAL),
    01422     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01423                       SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01424     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01425                       SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01426     NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01427                       SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01428     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01429   EndContainer(),
    01430 };
    01431
    01432 static const WindowDesc _orders_desc(
    01433   WDP_AUTO, 384, 100,
    01434   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01435   0,
    01436   _nested_orders_widgets, lengthof(_nested_orders_widgets)
    01437 );
    01438
    01440 static const NWidgetPart _nested_other_orders_widgets[] = {
    01441   NWidget(NWID_HORIZONTAL),
    01442     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01443     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01444     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01445     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01446     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01447   EndContainer(),
    01448   NWidget(NWID_HORIZONTAL),
    01449     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01450     NWidget(NWID_VERTICAL),
    01451       NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01452       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01453     EndContainer(),
    01454   EndContainer(),
    01455 };
    01456
    01457 static const WindowDesc _other_orders_desc(
    01458   WDP_AUTO, 384, 86,
    01459   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01460   WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
    01461   _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets)
    01462 );
    01463
    01464 void ShowOrdersWindow(const Vehicle *v)
    01465 {
    01466   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01467   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01468   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01469
    01470   if (v->owner != _local_company) {
    01471     new OrdersWindow(&_other_orders_desc, v);
    01472   } else {
    01473     new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
    01474   }
    01475 }