# order_gui.cpp

Go to the documentation of this file.

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