# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 19585 2010-04-08 15:40:46Z 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     if (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) return;
    00625
    00626     VehicleOrderID sel_ord = this->OrderGetSel();
    00627     const Order *order = this->vehicle->GetOrder(sel_ord);
    00628
    00629     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00630
    00631     /* Keypress if negative, so 'toggle' to the next */
    00632     if (non_stop < 0) {
    00633       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00634     }
    00635
    00636     this->SetWidgetDirty(ORDER_WIDGET_NON_STOP);
    00637     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 16), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00638   }
    00639
    00645   void OrderClick_Skip(int i)
    00646   {
    00647     /* Don't skip when there's nothing to skip */
    00648     if (_ctrl_pressed && this->vehicle->cur_order_index == this->OrderGetSel()) return;
    00649     if (this->vehicle->GetNumOrders() <= 1) return;
    00650
    00651     DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_order_index + 1) % this->vehicle->GetNumOrders()),
    00652         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
    00653   }
    00654
    00659   void OrderClick_Delete(int i)
    00660   {
    00661     /* When networking, move one order lower */
    00662     int selected = this->selected_order + (int)_networking;
    00663
    00664     if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
    00665       this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
    00666       this->UpdateButtonState();
    00667     }
    00668   }
    00669
    00675   void OrderClick_Refit(int i)
    00676   {
    00677     if (_ctrl_pressed) {
    00678       /* Cancel refitting */
    00679       DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00680     } else {
    00681       ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this);
    00682     }
    00683   }
    00684   typedef void (OrdersWindow::*Handler)(int);
    00685   struct KeyToEvent {
    00686     uint16 keycode;
    00687     Handler proc;
    00688   };
    00689
    00690 public:
    00691   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window()
    00692   {
    00693     this->vehicle = v;
    00694
    00695     this->InitNested(desc, v->index);
    00696
    00697     this->selected_order = -1;
    00698     this->owner = v->owner;
    00699
    00700     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00701       /* If there are less than 2 station, make Go To active. */
    00702       int station_orders = 0;
    00703       const Order *order;
    00704       FOR_VEHICLE_ORDERS(v, order) {
    00705         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00706       }
    00707
    00708       if (station_orders < 2) this->OrderClick_Goto(0);
    00709     }
    00710     this->OnInvalidateData(-2);
    00711   }
    00712
    00713   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00714   {
    00715     switch (widget) {
    00716       case ORDER_WIDGET_TIMETABLE_VIEW:
    00717         if (!_settings_game.order.timetabling) size->width = 0;
    00718         break;
    00719
    00720       case ORDER_WIDGET_ORDER_LIST:
    00721         resize->height = FONT_HEIGHT_NORMAL;
    00722         size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00723         break;
    00724
    00725       case ORDER_WIDGET_COND_VARIABLE: {
    00726         Dimension d = {0, 0};
    00727         for (int i = 0; _order_conditional_variable[i] != INVALID_STRING_ID; i++) {
    00728           d = maxdim(d, GetStringBoundingBox(_order_conditional_variable[i]));
    00729         }
    00730         d.width += padding.width;
    00731         d.height += padding.height;
    00732         *size = maxdim(*size, d);
    00733         break;
    00734       }
    00735
    00736       case ORDER_WIDGET_COND_COMPARATOR: {
    00737         Dimension d = {0, 0};
    00738         for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
    00739           d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
    00740         }
    00741         d.width += padding.width;
    00742         d.height += padding.height;
    00743         *size = maxdim(*size, d);
    00744         break;
    00745       }
    00746     }
    00747   }
    00748
    00749   virtual void OnInvalidateData(int data)
    00750   {
    00751     switch (data) {
    00752       case 0:
    00753         /* Autoreplace replaced the vehicle */
    00754         this->vehicle = Vehicle::Get(this->window_number);
    00755         break;
    00756
    00757       case -1:
    00758         /* Removed / replaced all orders (after deleting / sharing) */
    00759         if (this->selected_order == -1) break;
    00760
    00761         this->DeleteChildWindows();
    00762         HideDropDownMenu(this);
    00763         this->selected_order = -1;
    00764         break;
    00765
    00766       case -2:
    00767         /* Some other order changes */
    00768         break;
    00769
    00770       default: {
    00771         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00772          * the order is being created / removed */
    00773         if (this->selected_order == -1) break;
    00774
    00775         VehicleOrderID from = GB(data, 0, 8);
    00776         VehicleOrderID to   = GB(data, 8, 8);
    00777
    00778         if (from == to) break; // no need to change anything
    00779
    00780         if (from != this->selected_order) {
    00781           /* Moving from preceding order? */
    00782           this->selected_order -= (int)(from <= this->selected_order);
    00783           /* Moving to   preceding order? */
    00784           this->selected_order += (int)(to   <= this->selected_order);
    00785           break;
    00786         }
    00787
    00788         /* Now we are modifying the selected order */
    00789         if (to == INVALID_VEH_ORDER_ID) {
    00790           /* Deleting selected order */
    00791           this->DeleteChildWindows();
    00792           HideDropDownMenu(this);
    00793           this->selected_order = -1;
    00794           break;
    00795         }
    00796
    00797         /* Moving selected order */
    00798         this->selected_order = to;
    00799       } break;
    00800     }
    00801
    00802     this->vscroll.SetCount(this->vehicle->GetNumOrders() + 1);
    00803     this->UpdateButtonState();
    00804   }
    00805
    00806   void UpdateButtonState()
    00807   {
    00808     if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
    00809
    00810     bool shared_orders = this->vehicle->IsOrderListShared();
    00811     int sel = this->OrderGetSel();
    00812     const Order *order = this->vehicle->GetOrder(sel);
    00813
    00814     /* Second row. */
    00815     /* skip */
    00816     this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1);
    00817
    00818     /* delete */
    00819     this->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
    00820         (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00821
    00822     /* First row. */
    00823     this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
    00824     this->RaiseWidget(ORDER_WIDGET_UNLOAD);
    00825     this->RaiseWidget(ORDER_WIDGET_SERVICE);
    00826
    00827     /* Selection widgets. */
    00828     /* Train or road vehicle. */
    00829     NWidgetStacked *left_sel   = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_LEFT);
    00830     NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_MIDDLE);
    00831     NWidgetStacked *right_sel  = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_RIGHT);
    00832     /* Ship or airplane. */
    00833     NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(ORDER_WIDGET_SEL_TOP_ROW);
    00834     assert(row_sel != NULL || (left_sel != NULL && middle_sel != NULL && right_sel != NULL));
    00835
    00836
    00837     if (order == NULL) {
    00838       if (row_sel != NULL) {
    00839         row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00840       } else {
    00841         left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00842         middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00843         right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00844         this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00845         this->RaiseWidget(ORDER_WIDGET_NON_STOP);
    00846       }
    00847       this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00848       this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00849     } else {
    00850       this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    00851       this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    00852
    00853       switch (order->GetType()) {
    00854         case OT_GOTO_STATION:
    00855           if (row_sel != NULL) {
    00856             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00857           } else {
    00858             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00859             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00860             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00861             this->EnableWidget(ORDER_WIDGET_NON_STOP);
    00862             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00863           }
    00864           this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    00865           this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    00866           break;
    00867
    00868         case OT_GOTO_WAYPOINT:
    00869           if (row_sel != NULL) {
    00870             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00871           } else {
    00872             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00873             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00874             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00875             this->EnableWidget(ORDER_WIDGET_NON_STOP);
    00876             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00877           }
    00878           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00879           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00880           break;
    00881
    00882         case OT_GOTO_DEPOT:
    00883           if (row_sel != NULL) {
    00884             row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
    00885           } else {
    00886             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00887             middle_sel->SetDisplayedPlane(DP_MIDDLE_REFIT);
    00888             right_sel->SetDisplayedPlane(DP_RIGHT_SERVICE);
    00889             this->EnableWidget(ORDER_WIDGET_NON_STOP);
    00890             this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00891           }
    00892           this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    00893           break;
    00894
    00895         case OT_CONDITIONAL: {
    00896           if (row_sel != NULL) {
    00897             row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
    00898           } else {
    00899             left_sel->SetDisplayedPlane(DP_LEFT_CONDVAR);
    00900             middle_sel->SetDisplayedPlane(DP_MIDDLE_COMPARE);
    00901             right_sel->SetDisplayedPlane(DP_RIGHT_CONDVAL);
    00902           }
    00903           OrderConditionVariable ocv = order->GetConditionVariable();
    00904           /* Set the strings for the dropdown boxes. */
    00905           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_VARIABLE)->widget_data   = _order_conditional_variable[order == NULL ? 0 : ocv];
    00906           this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    00907           this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    00908           this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    00909           break;
    00910         }
    00911
    00912         default: // every other order
    00913           if (row_sel != NULL) {
    00914             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00915           } else {
    00916             left_sel->SetDisplayedPlane(DP_LEFT_NONSTOP);
    00917             middle_sel->SetDisplayedPlane(DP_MIDDLE_LOAD);
    00918             right_sel->SetDisplayedPlane(DP_RIGHT_UNLOAD);
    00919             this->DisableWidget(ORDER_WIDGET_NON_STOP);
    00920           }
    00921           this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
    00922           this->DisableWidget(ORDER_WIDGET_UNLOAD);
    00923           break;
    00924       }
    00925     }
    00926
    00927     /* Disable list of vehicles with the same shared orders if there is no list */
    00928     this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
    00929
    00930     this->SetDirty();
    00931   }
    00932
    00933   virtual void OnPaint()
    00934   {
    00935     if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window.
    00936     this->DrawWidgets();
    00937   }
    00938
    00939   virtual void DrawWidget(const Rect &r, int widget) const
    00940   {
    00941     if (widget != ORDER_WIDGET_ORDER_LIST) return;
    00942
    00943     bool rtl = _dynlang.text_dir == TD_RTL;
    00944     SetDParam(0, 99);
    00945     int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
    00946     int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
    00947
    00948     int y = r.top + WD_FRAMERECT_TOP;
    00949     int line_height = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST)->resize_y;
    00950
    00951     int i = this->vscroll.GetPosition();
    00952     const Order *order = this->vehicle->GetOrder(i);
    00953     StringID str;
    00954     while (order != NULL) {
    00955       /* Don't draw anything if it extends past the end of the window. */
    00956       if (!this->vscroll.IsVisible(i)) break;
    00957
    00958       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
    00959       y += line_height;
    00960
    00961       i++;
    00962       order = order->next;
    00963     }
    00964
    00965     if (this->vscroll.IsVisible(i)) {
    00966       str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
    00967       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);
    00968     }
    00969   }
    00970
    00971   virtual void SetStringParameters(int widget) const
    00972   {
    00973     switch (widget) {
    00974       case ORDER_WIDGET_COND_VALUE: {
    00975         int sel = this->OrderGetSel();
    00976         const Order *order = this->vehicle->GetOrder(sel);
    00977
    00978         if (order != NULL && order->IsType(OT_CONDITIONAL)) {
    00979           uint value = order->GetConditionValue();
    00980           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00981           SetDParam(0, value);
    00982         }
    00983         break;
    00984       }
    00985
    00986       case ORDER_WIDGET_CAPTION:
    00987         SetDParam(0, this->vehicle->index);
    00988         break;
    00989     }
    00990   }
    00991
    00992   virtual void OnClick(Point pt, int widget, int click_count)
    00993   {
    00994     switch (widget) {
    00995       case ORDER_WIDGET_ORDER_LIST: {
    00996         ResetObjectToPlace();
    00997
    00998         int sel = this->GetOrderFromPt(pt.y);
    00999
    01000         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    01001           TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
    01002           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    01003           return;
    01004         }
    01005
    01006         /* This order won't be selected any more, close all child windows and dropdowns */
    01007         this->DeleteChildWindows();
    01008         HideDropDownMenu(this);
    01009
    01010         if (sel == INVALID_ORDER || this->vehicle->owner != _local_company) {
    01011           /* Deselect clicked order */
    01012           this->selected_order = -1;
    01013         } else if (sel == this->selected_order) {
    01014           if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
    01015             DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
    01016                 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
    01017                 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01018           }
    01019         } else {
    01020           /* Select clicked order */
    01021           this->selected_order = sel;
    01022
    01023           if (this->vehicle->owner == _local_company) {
    01024             /* Activate drag and drop */
    01025             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
    01026           }
    01027         }
    01028
    01029         this->UpdateButtonState();
    01030       } break;
    01031
    01032       case ORDER_WIDGET_SKIP:
    01033         this->OrderClick_Skip(0);
    01034         break;
    01035
    01036       case ORDER_WIDGET_DELETE:
    01037         this->OrderClick_Delete(0);
    01038         break;
    01039
    01040       case ORDER_WIDGET_NON_STOP:
    01041         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01042           this->OrderClick_Nonstop(-1);
    01043         } else {
    01044           const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01045           ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP, 0,
    01046                           o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
    01047         }
    01048         break;
    01049
    01050       case ORDER_WIDGET_GOTO:
    01051         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01052           this->OrderClick_Goto(0);
    01053         } else {
    01054           ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, ORDER_WIDGET_GOTO, 0, 0);
    01055         }
    01056         break;
    01057
    01058       case ORDER_WIDGET_FULL_LOAD:
    01059         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01060           this->OrderClick_FullLoad(-1);
    01061         } else {
    01062           ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD, 0, 2);
    01063         }
    01064         break;
    01065
    01066       case ORDER_WIDGET_UNLOAD:
    01067         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01068           this->OrderClick_Unload(-1);
    01069         } else {
    01070           ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD, 0, 8);
    01071         }
    01072         break;
    01073
    01074       case ORDER_WIDGET_REFIT:
    01075         this->OrderClick_Refit(0);
    01076         break;
    01077
    01078       case ORDER_WIDGET_SERVICE:
    01079         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01080           this->OrderClick_Service(-1);
    01081         } else {
    01082           ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE, 0, 0);
    01083         }
    01084         break;
    01085
    01086       case ORDER_WIDGET_TIMETABLE_VIEW:
    01087         ShowTimetableWindow(this->vehicle);
    01088         break;
    01089
    01090       case ORDER_WIDGET_COND_VARIABLE:
    01091         ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
    01092         break;
    01093
    01094       case ORDER_WIDGET_COND_COMPARATOR: {
    01095         const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01096         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    01097       } break;
    01098
    01099       case ORDER_WIDGET_COND_VALUE: {
    01100         const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
    01101         uint value = order->GetConditionValue();
    01102         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01103         SetDParam(0, value);
    01104         ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, 100, this, CS_NUMERAL, QSF_NONE);
    01105       } break;
    01106
    01107       case ORDER_WIDGET_SHARED_ORDER_LIST:
    01108         ShowVehicleListWindow(this->vehicle);
    01109         break;
    01110     }
    01111   }
    01112
    01113   virtual void OnQueryTextFinished(char *str)
    01114   {
    01115     if (!StrEmpty(str)) {
    01116       VehicleOrderID sel = this->OrderGetSel();
    01117       uint value = atoi(str);
    01118
    01119       switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
    01120         case OCV_MAX_SPEED:
    01121           value = ConvertDisplaySpeedToSpeed(value);
    01122           break;
    01123
    01124         case OCV_RELIABILITY:
    01125         case OCV_LOAD_PERCENTAGE:
    01126           value = Clamp(value, 0, 100);
    01127
    01128         default:
    01129           break;
    01130       }
    01131       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));
    01132     }
    01133   }
    01134
    01135   virtual void OnDropdownSelect(int widget, int index)
    01136   {
    01137     switch (widget) {
    01138       case ORDER_WIDGET_NON_STOP:
    01139         this->OrderClick_Nonstop(index);
    01140         break;
    01141
    01142       case ORDER_WIDGET_FULL_LOAD:
    01143         this->OrderClick_FullLoad(index);
    01144         break;
    01145
    01146       case ORDER_WIDGET_UNLOAD:
    01147         this->OrderClick_Unload(index);
    01148         break;
    01149
    01150       case ORDER_WIDGET_GOTO:
    01151         switch (index) {
    01152           case 0: this->OrderClick_Goto(0); break;
    01153           case 1: this->OrderClick_NearestDepot(0); break;
    01154           case 2: this->OrderClick_Conditional(0); break;
    01155           default: NOT_REACHED();
    01156         }
    01157         break;
    01158
    01159       case ORDER_WIDGET_SERVICE:
    01160         this->OrderClick_Service(index);
    01161         break;
    01162
    01163       case ORDER_WIDGET_COND_VARIABLE:
    01164         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));
    01165         break;
    01166
    01167       case ORDER_WIDGET_COND_COMPARATOR:
    01168         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));
    01169         break;
    01170     }
    01171   }
    01172
    01173   virtual void OnDragDrop(Point pt, int widget)
    01174   {
    01175     switch (widget) {
    01176       case ORDER_WIDGET_ORDER_LIST: {
    01177         int from_order = this->OrderGetSel();
    01178         int to_order = this->GetOrderFromPt(pt.y);
    01179
    01180         if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) &&
    01181             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
    01182           this->selected_order = -1;
    01183           this->UpdateButtonState();
    01184         }
    01185       } break;
    01186
    01187       case ORDER_WIDGET_DELETE:
    01188         this->OrderClick_Delete(0);
    01189         break;
    01190     }
    01191
    01192     ResetObjectToPlace();
    01193   }
    01194
    01195   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01196   {
    01197     static const KeyToEvent keytoevent[] = {
    01198       {'D', &OrdersWindow::OrderClick_Skip},
    01199       {'F', &OrdersWindow::OrderClick_Delete},
    01200       {'G', &OrdersWindow::OrderClick_Goto},
    01201       {'H', &OrdersWindow::OrderClick_Nonstop},
    01202       {'J', &OrdersWindow::OrderClick_FullLoad},
    01203       {'K', &OrdersWindow::OrderClick_Unload},
    01204       //('?', &OrdersWindow::OrderClick_Service},
    01205     };
    01206
    01207     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01208
    01209     for (uint i = 0; i < lengthof(keytoevent); i++) {
    01210       if (keycode == keytoevent[i].keycode) {
    01211         (this->*(keytoevent[i].proc))(-1);
    01212         return ES_HANDLED;
    01213       }
    01214     }
    01215     return ES_NOT_HANDLED;
    01216   }
    01217
    01218   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01219   {
    01220     if (this->goto_type == OPOS_GOTO) {
    01221       /* check if we're clicking on a vehicle first.. clone orders in that case. */
    01222       const Vehicle *v = CheckMouseOverVehicle();
    01223       if (v != NULL && this->HandleOrderVehClick(v)) return;
    01224
    01225       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01226       if (cmd.IsType(OT_NOTHING)) return;
    01227
    01228       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))) {
    01229         /* With quick goto the Go To button stays active */
    01230         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01231       }
    01232     }
    01233   }
    01234
    01235   virtual void OnPlaceObjectAbort()
    01236   {
    01237     if (this->goto_type == OPOS_CONDITIONAL) {
    01238       this->goto_type = OPOS_GOTO;
    01239       NWidgetBase *nwid = this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST);
    01240       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)) {
    01241         int order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01242         if (order_id != INVALID_ORDER) {
    01243           Order order;
    01244           order.next = NULL;
    01245           order.index = 0;
    01246           order.MakeConditional(order_id);
    01247
    01248           DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    01249         }
    01250       }
    01251     }
    01252     this->RaiseWidget(ORDER_WIDGET_GOTO);
    01253     this->SetWidgetDirty(ORDER_WIDGET_GOTO);
    01254   }
    01255
    01256   virtual void OnMouseLoop()
    01257   {
    01258     const Vehicle *v = _place_clicked_vehicle;
    01259     /*
    01260      * Check if we clicked on a vehicle
    01261      * and if the GOTO button of this window is pressed
    01262      * This is because of all open order windows WE_MOUSELOOP is called
    01263      * and if you have 3 windows open, and this check is not done
    01264      * the order is copied to the last open window instead of the
    01265      * one where GOTO is enabled
    01266      */
    01267     if (v != NULL && this->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
    01268       _place_clicked_vehicle = NULL;
    01269       this->HandleOrderVehClick(v);
    01270     }
    01271   }
    01272
    01273   virtual void OnResize()
    01274   {
    01275     /* Update the scroll bar */
    01276     this->vscroll.SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
    01277   }
    01278
    01279   virtual void OnTimeout()
    01280   {
    01281     static const int raise_widgets[] = {
    01282       ORDER_WIDGET_TIMETABLE_VIEW, ORDER_WIDGET_SKIP, ORDER_WIDGET_DELETE, ORDER_WIDGET_REFIT, ORDER_WIDGET_SHARED_ORDER_LIST, WIDGET_LIST_END,
    01283     };
    01284
    01285     /* Unclick all buttons in raise_widgets[]. */
    01286     for (const int *widnum = raise_widgets; *widnum != WIDGET_LIST_END; widnum++) {
    01287       if (this->IsWidgetLowered(*widnum)) {
    01288         this->RaiseWidget(*widnum);
    01289         this->SetWidgetDirty(*widnum);
    01290       }
    01291     }
    01292   }
    01293 };
    01294
    01296 static const NWidgetPart _nested_orders_train_widgets[] = {
    01297   NWidget(NWID_HORIZONTAL),
    01298     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01299     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01300     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01301     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01302     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01303   EndContainer(),
    01304   NWidget(NWID_HORIZONTAL),
    01305     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01306     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01307   EndContainer(),
    01308
    01309   /* First button row. */
    01310   NWidget(NWID_HORIZONTAL),
    01311     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01312       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_LEFT),
    01313         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_NON_STOP), SetMinimalSize(124, 12), SetFill(1, 0),
    01314                             SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
    01315         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01316                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01317       EndContainer(),
    01318       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_MIDDLE),
    01319         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01320                             SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01321         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(124, 12), SetFill(1, 0),
    01322                             SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01323         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01324                             SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01325       EndContainer(),
    01326       NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_RIGHT),
    01327         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01328                             SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01329         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01330                             SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01331         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01332                             SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01333       EndContainer(),
    01334     EndContainer(),
    01335     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),
    01336   EndContainer(),
    01337
    01338   /* Second button row. */
    01339   NWidget(NWID_HORIZONTAL),
    01340     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01341       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01342                           SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01343       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01344                           SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01345       NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01346                           SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01347     EndContainer(),
    01348     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01349   EndContainer(),
    01350 };
    01351
    01352 static const WindowDesc _orders_train_desc(
    01353   WDP_AUTO, 384, 100,
    01354   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01355   WDF_CONSTRUCTION,
    01356   _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets)
    01357 );
    01358
    01360 static const NWidgetPart _nested_orders_widgets[] = {
    01361   NWidget(NWID_HORIZONTAL),
    01362     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01363     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01364     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01365     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01366     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01367   EndContainer(),
    01368   NWidget(NWID_HORIZONTAL),
    01369     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01370     NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01371   EndContainer(),
    01372
    01373   /* First button row. */
    01374   NWidget(NWID_HORIZONTAL),
    01375     NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_ROW),
    01376       /* load + unload buttons. */
    01377       NWidget(NWID_HORIZONTAL),
    01378         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01379                           SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01380         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(186, 12), SetFill(1, 0),
    01381                           SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01382       EndContainer(),
    01383       /* Refit + service buttons. */
    01384       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01385         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
    01386                           SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01387         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01388                           SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01389       EndContainer(),
    01390
    01391       /* Buttons for setting a condition. */
    01392       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01393         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01394                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01395         NWidget(WWT_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01396                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01397         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01398                           SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01399       EndContainer(),
    01400     EndContainer(),
    01401
    01402     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),
    01403   EndContainer(),
    01404
    01405   /* Second button row. */
    01406   NWidget(NWID_HORIZONTAL),
    01407     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01408                       SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01409     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01410                       SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01411     NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01412                       SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01413     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01414   EndContainer(),
    01415 };
    01416
    01417 static const WindowDesc _orders_desc(
    01418   WDP_AUTO, 384, 100,
    01419   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01420   WDF_CONSTRUCTION,
    01421   _nested_orders_widgets, lengthof(_nested_orders_widgets)
    01422 );
    01423
    01425 static const NWidgetPart _nested_other_orders_widgets[] = {
    01426   NWidget(NWID_HORIZONTAL),
    01427     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01428     NWidget(WWT_CAPTION, COLOUR_GREY, ORDER_WIDGET_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01429     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01430     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01431     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01432   EndContainer(),
    01433   NWidget(NWID_HORIZONTAL),
    01434     NWidget(WWT_PANEL, COLOUR_GREY, ORDER_WIDGET_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), EndContainer(),
    01435     NWidget(NWID_VERTICAL),
    01436       NWidget(WWT_SCROLLBAR, COLOUR_GREY, ORDER_WIDGET_SCROLLBAR),
    01437       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01438     EndContainer(),
    01439   EndContainer(),
    01440 };
    01441
    01442 static const WindowDesc _other_orders_desc(
    01443   WDP_AUTO, 384, 86,
    01444   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01445   WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION,
    01446   _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets)
    01447 );
    01448
    01449 void ShowOrdersWindow(const Vehicle *v)
    01450 {
    01451   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01452   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01453   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01454
    01455   if (v->owner != _local_company) {
    01456     new OrdersWindow(&_other_orders_desc, v);
    01457   } else {
    01458     new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
    01459   }
    01460 }