# order_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: order_gui.cpp 25498 2013-06-28 19:21:24Z 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_map.h"
    00016 #include "roadveh.h"
    00017 #include "timetable.h"
    00018 #include "strings_func.h"
    00019 #include "company_func.h"
    00020 #include "widgets/dropdown_type.h"
    00021 #include "widgets/dropdown_func.h"
    00022 #include "textbuf_gui.h"
    00023 #include "string_func.h"
    00024 #include "tilehighlight_func.h"
    00025 #include "network/network.h"
    00026 #include "station_base.h"
    00027 #include "waypoint_base.h"
    00028 #include "core/geometry_func.hpp"
    00029 #include "hotkeys.h"
    00030 #include "aircraft.h"
    00031 #include "engine_func.h"
    00032
    00033 #include "widgets/order_widget.h"
    00034
    00035
    00037 static const StringID _station_load_types[][5][5] = {
    00038   {
    00039     /* No refitting. */
    00040     {
    00041       STR_EMPTY,
    00042       INVALID_STRING_ID,
    00043       STR_ORDER_FULL_LOAD,
    00044       STR_ORDER_FULL_LOAD_ANY,
    00045       STR_ORDER_NO_LOAD,
    00046     }, {
    00047       STR_ORDER_UNLOAD,
    00048       INVALID_STRING_ID,
    00049       STR_ORDER_UNLOAD_FULL_LOAD,
    00050       STR_ORDER_UNLOAD_FULL_LOAD_ANY,
    00051       STR_ORDER_UNLOAD_NO_LOAD,
    00052     }, {
    00053       STR_ORDER_TRANSFER,
    00054       INVALID_STRING_ID,
    00055       STR_ORDER_TRANSFER_FULL_LOAD,
    00056       STR_ORDER_TRANSFER_FULL_LOAD_ANY,
    00057       STR_ORDER_TRANSFER_NO_LOAD,
    00058     }, {
    00059       /* Unload and transfer do not work together. */
    00060       INVALID_STRING_ID,
    00061       INVALID_STRING_ID,
    00062       INVALID_STRING_ID,
    00063       INVALID_STRING_ID,
    00064     }, {
    00065       STR_ORDER_NO_UNLOAD,
    00066       INVALID_STRING_ID,
    00067       STR_ORDER_NO_UNLOAD_FULL_LOAD,
    00068       STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
    00069       STR_ORDER_NO_UNLOAD_NO_LOAD,
    00070     }
    00071   }, {
    00072     /* With auto-refitting. No loading and auto-refitting do not work together. */
    00073     {
    00074       STR_ORDER_AUTO_REFIT,
    00075       INVALID_STRING_ID,
    00076       STR_ORDER_FULL_LOAD_REFIT,
    00077       STR_ORDER_FULL_LOAD_ANY_REFIT,
    00078       INVALID_STRING_ID,
    00079     }, {
    00080       STR_ORDER_UNLOAD_REFIT,
    00081       INVALID_STRING_ID,
    00082       STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
    00083       STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
    00084       INVALID_STRING_ID,
    00085     }, {
    00086       STR_ORDER_TRANSFER_REFIT,
    00087       INVALID_STRING_ID,
    00088       STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
    00089       STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
    00090       INVALID_STRING_ID,
    00091     }, {
    00092       /* Unload and transfer do not work together. */
    00093       INVALID_STRING_ID,
    00094       INVALID_STRING_ID,
    00095       INVALID_STRING_ID,
    00096       INVALID_STRING_ID,
    00097     }, {
    00098       STR_ORDER_NO_UNLOAD_REFIT,
    00099       INVALID_STRING_ID,
    00100       STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
    00101       STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
    00102       INVALID_STRING_ID,
    00103     }
    00104   }
    00105 };
    00106
    00107 static const StringID _order_non_stop_drowdown[] = {
    00108   STR_ORDER_GO_TO,
    00109   STR_ORDER_GO_NON_STOP_TO,
    00110   STR_ORDER_GO_VIA,
    00111   STR_ORDER_GO_NON_STOP_VIA,
    00112   INVALID_STRING_ID
    00113 };
    00114
    00115 static const StringID _order_full_load_drowdown[] = {
    00116   STR_ORDER_DROP_LOAD_IF_POSSIBLE,
    00117   STR_EMPTY,
    00118   STR_ORDER_DROP_FULL_LOAD_ALL,
    00119   STR_ORDER_DROP_FULL_LOAD_ANY,
    00120   STR_ORDER_DROP_NO_LOADING,
    00121   INVALID_STRING_ID
    00122 };
    00123
    00124 static const StringID _order_unload_drowdown[] = {
    00125   STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
    00126   STR_ORDER_DROP_UNLOAD,
    00127   STR_ORDER_DROP_TRANSFER,
    00128   STR_EMPTY,
    00129   STR_ORDER_DROP_NO_UNLOADING,
    00130   INVALID_STRING_ID
    00131 };
    00132
    00133 static const StringID _order_goto_dropdown[] = {
    00134   STR_ORDER_GO_TO,
    00135   STR_ORDER_GO_TO_NEAREST_DEPOT,
    00136   STR_ORDER_CONDITIONAL,
    00137   STR_ORDER_SHARE,
    00138   INVALID_STRING_ID
    00139 };
    00140
    00141 static const StringID _order_goto_dropdown_aircraft[] = {
    00142   STR_ORDER_GO_TO,
    00143   STR_ORDER_GO_TO_NEAREST_HANGAR,
    00144   STR_ORDER_CONDITIONAL,
    00145   STR_ORDER_SHARE,
    00146   INVALID_STRING_ID
    00147 };
    00148
    00150 static const OrderConditionVariable _order_conditional_variable[] = {
    00151   OCV_LOAD_PERCENTAGE,
    00152   OCV_RELIABILITY,
    00153   OCV_MAX_SPEED,
    00154   OCV_AGE,
    00155   OCV_REMAINING_LIFETIME,
    00156   OCV_REQUIRES_SERVICE,
    00157   OCV_UNCONDITIONALLY,
    00158 };
    00159
    00160 static const StringID _order_conditional_condition[] = {
    00161   STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
    00162   STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
    00163   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
    00164   STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
    00165   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
    00166   STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
    00167   STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
    00168   STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
    00169   INVALID_STRING_ID,
    00170 };
    00171
    00172 extern uint ConvertSpeedToDisplaySpeed(uint speed);
    00173 extern uint ConvertDisplaySpeedToSpeed(uint speed);
    00174
    00175 static const StringID _order_depot_action_dropdown[] = {
    00176   STR_ORDER_DROP_GO_ALWAYS_DEPOT,
    00177   STR_ORDER_DROP_SERVICE_DEPOT,
    00178   STR_ORDER_DROP_HALT_DEPOT,
    00179   INVALID_STRING_ID
    00180 };
    00181
    00182 static int DepotActionStringIndex(const Order *order)
    00183 {
    00184   if (order->GetDepotActionType() & ODATFB_HALT) {
    00185     return DA_STOP;
    00186   } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00187     return DA_SERVICE;
    00188   } else {
    00189     return DA_ALWAYS_GO;
    00190   }
    00191 }
    00192
    00193 static const StringID _order_refit_action_dropdown[] = {
    00194   STR_ORDER_DROP_REFIT_AUTO,
    00195   STR_ORDER_DROP_REFIT_AUTO_ANY,
    00196   INVALID_STRING_ID
    00197 };
    00198
    00211 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
    00212 {
    00213   bool rtl = _current_text_dir == TD_RTL;
    00214
    00215   SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
    00216   Dimension sprite_size = GetSpriteSize(sprite);
    00217   if (v->cur_real_order_index == order_index) {
    00218     DrawSprite(sprite, PAL_NONE, rtl ? right -     sprite_size.width : left,                     y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00219     DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00220   } else if (v->cur_implicit_order_index == order_index) {
    00221     DrawSprite(sprite, PAL_NONE, rtl ? right -     sprite_size.width : left,                     y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
    00222   }
    00223
    00224   TextColour colour = TC_BLACK;
    00225   if (order->IsType(OT_IMPLICIT)) {
    00226     colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
    00227   } else if (selected) {
    00228     colour = TC_WHITE;
    00229   }
    00230
    00231   SetDParam(0, order_index + 1);
    00232   DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
    00233
    00234   SetDParam(5, STR_EMPTY);
    00235   SetDParam(8, STR_EMPTY);
    00236
    00237   /* Check range for aircraft. */
    00238   if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
    00239     const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
    00240     if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
    00241   }
    00242
    00243   switch (order->GetType()) {
    00244     case OT_DUMMY:
    00245       SetDParam(0, STR_INVALID_ORDER);
    00246       SetDParam(1, order->GetDestination());
    00247       break;
    00248
    00249     case OT_IMPLICIT:
    00250       SetDParam(0, STR_ORDER_GO_TO_STATION);
    00251       SetDParam(1, STR_ORDER_GO_TO);
    00252       SetDParam(2, order->GetDestination());
    00253       SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
    00254       break;
    00255
    00256     case OT_GOTO_STATION: {
    00257       OrderLoadFlags load = order->GetLoadType();
    00258       OrderUnloadFlags unload = order->GetUnloadType();
    00259
    00260       SetDParam(0, STR_ORDER_GO_TO_STATION);
    00261       SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
    00262       SetDParam(2, order->GetDestination());
    00263
    00264       if (timetable) {
    00265         SetDParam(3, STR_EMPTY);
    00266
    00267         if (order->wait_time > 0) {
    00268           SetDParam(5, STR_TIMETABLE_STAY_FOR);
    00269           SetTimetableParams(6, 7, order->wait_time);
    00270         }
    00271       } else {
    00272         SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
    00273         if (order->IsRefit()) {
    00274           SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
    00275         }
    00276         if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
    00277           SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
    00278         }
    00279       }
    00280       break;
    00281     }
    00282
    00283     case OT_GOTO_DEPOT:
    00284       if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
    00285         SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
    00286         if (v->type == VEH_AIRCRAFT) {
    00287           SetDParam(2, STR_ORDER_NEAREST_HANGAR);
    00288           SetDParam(3, STR_EMPTY);
    00289         } else {
    00290           SetDParam(2, STR_ORDER_NEAREST_DEPOT);
    00291           SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
    00292         }
    00293       } else {
    00294         SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
    00295         SetDParam(2, v->type);
    00296         SetDParam(3, order->GetDestination());
    00297       }
    00298
    00299       if (order->GetDepotOrderType() & ODTFB_SERVICE) {
    00300         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
    00301       } else {
    00302         SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
    00303       }
    00304
    00305       if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
    00306         SetDParam(5, STR_ORDER_STOP_ORDER);
    00307       }
    00308
    00309       if (!timetable && order->IsRefit()) {
    00310         SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
    00311         SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
    00312       }
    00313       break;
    00314
    00315     case OT_GOTO_WAYPOINT:
    00316       SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
    00317       SetDParam(1, order->GetDestination());
    00318       break;
    00319
    00320     case OT_CONDITIONAL:
    00321       SetDParam(1, order->GetConditionSkipToOrder() + 1);
    00322       if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
    00323         SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
    00324       } else {
    00325         OrderConditionComparator occ = order->GetConditionComparator();
    00326         SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
    00327         SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
    00328         SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
    00329
    00330         uint value = order->GetConditionValue();
    00331         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    00332         SetDParam(4, value);
    00333       }
    00334
    00335       if (timetable && order->wait_time > 0) {
    00336         SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR);
    00337         SetTimetableParams(6, 7, order->wait_time);
    00338       } else {
    00339         SetDParam(5, STR_EMPTY);
    00340       }
    00341       break;
    00342
    00343     default: NOT_REACHED();
    00344   }
    00345
    00346   DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
    00347 }
    00348
    00349
    00350 static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
    00351 {
    00352   Order order;
    00353   order.next  = NULL;
    00354   order.index = 0;
    00355
    00356   /* check depot first */
    00357   switch (GetTileType(tile)) {
    00358     case MP_RAILWAY:
    00359       if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
    00360         if (IsRailDepot(tile)) {
    00361           order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00362               _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00363           if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00364           return order;
    00365         }
    00366       }
    00367       break;
    00368
    00369     case MP_ROAD:
    00370       if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
    00371         order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
    00372             _settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00373         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00374         return order;
    00375       }
    00376       break;
    00377
    00378     case MP_STATION:
    00379       if (v->type != VEH_AIRCRAFT) break;
    00380       if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
    00381         order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00382         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00383         return order;
    00384       }
    00385       break;
    00386
    00387     case MP_WATER:
    00388       if (v->type != VEH_SHIP) break;
    00389       if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
    00390         order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
    00391         if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
    00392         return order;
    00393       }
    00394       break;
    00395
    00396     default:
    00397       break;
    00398   }
    00399
    00400   /* check waypoint */
    00401   if (IsRailWaypointTile(tile) &&
    00402       v->type == VEH_TRAIN &&
    00403       IsTileOwner(tile, _local_company)) {
    00404     order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
    00405     if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
    00406     return order;
    00407   }
    00408
    00409   if ((IsBuoyTile(tile) && v->type == VEH_SHIP) || (IsRailWaypointTile(tile) && v->type == VEH_TRAIN)) {
    00410     order.MakeGoToWaypoint(GetStationIndex(tile));
    00411     return order;
    00412   }
    00413
    00414   if (IsTileType(tile, MP_STATION)) {
    00415     StationID st_index = GetStationIndex(tile);
    00416     const Station *st = Station::Get(st_index);
    00417
    00418     if (st->owner == _local_company || st->owner == OWNER_NONE) {
    00419       byte facil;
    00420       (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
    00421       (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
    00422       (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
    00423       (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
    00424       (facil = FACIL_TRUCK_STOP, 1);
    00425       if (st->facilities & facil) {
    00426         order.MakeGoToStation(st_index);
    00427         if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
    00428         if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    00429         order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
    00430         return order;
    00431       }
    00432     }
    00433   }
    00434
    00435   /* not found */
    00436   order.Free();
    00437   return order;
    00438 }
    00439
    00480 struct OrdersWindow : public Window {
    00481 private:
    00483   enum OrderPlaceObjectState {
    00484     OPOS_GOTO,
    00485     OPOS_CONDITIONAL,
    00486     OPOS_SHARE,
    00487   };
    00488
    00490   enum DisplayPane {
    00491     /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
    00492     DP_GROUNDVEHICLE_ROW_NORMAL      = 0,
    00493     DP_GROUNDVEHICLE_ROW_CONDITIONAL = 1,
    00494
    00495     /* WID_O_SEL_TOP_LEFT */
    00496     DP_LEFT_LOAD       = 0,
    00497     DP_LEFT_REFIT      = 1,
    00498
    00499     /* WID_O_SEL_TOP_MIDDLE */
    00500     DP_MIDDLE_UNLOAD   = 0,
    00501     DP_MIDDLE_SERVICE  = 1,
    00502
    00503     /* WID_O_SEL_TOP_RIGHT */
    00504     DP_RIGHT_EMPTY     = 0,
    00505     DP_RIGHT_REFIT     = 1,
    00506
    00507     /* WID_O_SEL_TOP_ROW */
    00508     DP_ROW_LOAD        = 0,
    00509     DP_ROW_DEPOT       = 1,
    00510     DP_ROW_CONDITIONAL = 2,
    00511
    00512     /* WID_O_SEL_BOTTOM_MIDDLE */
    00513     DP_BOTTOM_MIDDLE_DELETE       = 0,
    00514     DP_BOTTOM_MIDDLE_STOP_SHARING = 1,
    00515   };
    00516
    00517   int selected_order;
    00518   VehicleOrderID order_over;
    00519   OrderPlaceObjectState goto_type;
    00520   const Vehicle *vehicle;
    00521   Scrollbar *vscroll;
    00522   bool can_do_refit;
    00523   bool can_do_autorefit;
    00524
    00530   VehicleOrderID OrderGetSel() const
    00531   {
    00532     int num = this->selected_order;
    00533     return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
    00534   }
    00535
    00544   VehicleOrderID GetOrderFromPt(int y)
    00545   {
    00546     NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
    00547     int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
    00548
    00549     if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
    00550
    00551     sel += this->vscroll->GetPosition();
    00552
    00553     return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
    00554   }
    00555
    00560   void OrderClick_Goto(int i)
    00561   {
    00562     this->SetWidgetDirty(WID_O_GOTO);
    00563     this->ToggleWidgetLoweredState(WID_O_GOTO);
    00564     if (this->IsWidgetLowered(WID_O_GOTO)) {
    00565       SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_RECT | HT_VEHICLE, this);
    00566       this->goto_type = OPOS_GOTO;
    00567     } else {
    00568       ResetObjectToPlace();
    00569     }
    00570   }
    00571
    00576   void OrderClick_FullLoad(int load_type)
    00577   {
    00578     VehicleOrderID sel_ord = this->OrderGetSel();
    00579     const Order *order = this->vehicle->GetOrder(sel_ord);
    00580
    00581     if (order == NULL || order->GetLoadType() == load_type) return;
    00582
    00583     if (load_type < 0) {
    00584       load_type = order->GetLoadType() == OLF_LOAD_IF_POSSIBLE ? OLF_FULL_LOAD_ANY : OLF_LOAD_IF_POSSIBLE;
    00585     }
    00586     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00587   }
    00588
    00592   void OrderHotkey_NoLoad(int i)
    00593   {
    00594     this->OrderClick_FullLoad(OLFB_NO_LOAD);
    00595   }
    00596
    00600   void OrderClick_Service(int i)
    00601   {
    00602     VehicleOrderID sel_ord = this->OrderGetSel();
    00603
    00604     if (i < 0) {
    00605       const Order *order = this->vehicle->GetOrder(sel_ord);
    00606       if (order == NULL) return;
    00607       i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
    00608     }
    00609     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00610   }
    00611
    00616   void OrderClick_NearestDepot(int i)
    00617   {
    00618     Order order;
    00619     order.next = NULL;
    00620     order.index = 0;
    00621     order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
    00622         _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
    00623     order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
    00624
    00625     DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    00626   }
    00627
    00632   void OrderClick_Conditional(int i)
    00633   {
    00634     this->LowerWidget(WID_O_GOTO);
    00635     this->SetWidgetDirty(WID_O_GOTO);
    00636     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_NONE, this);
    00637     this->goto_type = OPOS_CONDITIONAL;
    00638   }
    00639
    00644   void OrderClick_Share(int i)
    00645   {
    00646     this->LowerWidget(WID_O_GOTO);
    00647     this->SetWidgetDirty(WID_O_GOTO);
    00648     SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, HT_VEHICLE, this);
    00649     this->goto_type = OPOS_SHARE;
    00650   }
    00651
    00655   void OrderClick_Unload(int unload_type)
    00656   {
    00657     VehicleOrderID sel_ord = this->OrderGetSel();
    00658     const Order *order = this->vehicle->GetOrder(sel_ord);
    00659
    00660     if (order == NULL || order->GetUnloadType() == unload_type) return;
    00661
    00662     if (unload_type < 0) {
    00663       unload_type = order->GetUnloadType() == OUF_UNLOAD_IF_POSSIBLE ? OUFB_UNLOAD : OUF_UNLOAD_IF_POSSIBLE;
    00664     }
    00665
    00666     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00667
    00668     /* Transfer orders with leave empty as default */
    00669     if (unload_type == OUFB_TRANSFER) {
    00670       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
    00671       this->SetWidgetDirty(WID_O_FULL_LOAD);
    00672     }
    00673   }
    00674
    00678   void OrderHotkey_Transfer(int i)
    00679   {
    00680     this->OrderClick_Unload(OUFB_TRANSFER);
    00681   }
    00682
    00686   void OrderHotkey_NoUnload(int i)
    00687   {
    00688     this->OrderClick_Unload(OUFB_NO_UNLOAD);
    00689   }
    00690
    00695   void OrderClick_Nonstop(int non_stop)
    00696   {
    00697     if (!this->vehicle->IsGroundVehicle()) return;
    00698
    00699     VehicleOrderID sel_ord = this->OrderGetSel();
    00700     const Order *order = this->vehicle->GetOrder(sel_ord);
    00701
    00702     if (order == NULL || order->GetNonStopType() == non_stop) return;
    00703
    00704     /* Keypress if negative, so 'toggle' to the next */
    00705     if (non_stop < 0) {
    00706       non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
    00707     }
    00708
    00709     this->SetWidgetDirty(WID_O_NON_STOP);
    00710     DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_NON_STOP | non_stop << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    00711   }
    00712
    00718   void OrderClick_Skip(int i)
    00719   {
    00720     /* Don't skip when there's nothing to skip */
    00721     if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
    00722     if (this->vehicle->GetNumOrders() <= 1) return;
    00723
    00724     DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
    00725         CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
    00726   }
    00727
    00732   void OrderClick_Delete(int i)
    00733   {
    00734     /* When networking, move one order lower */
    00735     int selected = this->selected_order + (int)_networking;
    00736
    00737     if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
    00738       this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
    00739       this->UpdateButtonState();
    00740     }
    00741   }
    00742
    00750   void OrderClick_StopSharing(int i)
    00751   {
    00752     /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
    00753     if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
    00754     /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
    00755     if (_ctrl_pressed) {
    00756       this->OrderClick_Delete(0);
    00757       return;
    00758     }
    00759
    00760     /* Get another vehicle that share orders with this vehicle. */
    00761     Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
    00762     /* Copy the order list of the other vehicle. */
    00763     if (DoCommandP(this->vehicle->tile, this->vehicle->index | CO_COPY << 30, other_shared->index, CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST))) {
    00764       this->UpdateButtonState();
    00765     }
    00766   }
    00767
    00774   void OrderClick_Refit(int i, bool auto_refit)
    00775   {
    00776     if (_ctrl_pressed) {
    00777       /* Cancel refitting */
    00778       DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
    00779     } else {
    00780       if (i == 1) { // Auto-refit to available cargo type.
    00781         DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
    00782       } else {
    00783         ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
    00784       }
    00785     }
    00786   }
    00787
    00789   void UpdateAutoRefitState()
    00790   {
    00791     this->can_do_refit = false;
    00792     this->can_do_autorefit = false;
    00793     for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
    00794       if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
    00795       if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
    00796     }
    00797   }
    00798
    00799 public:
    00800   OrdersWindow(const WindowDesc *desc, const Vehicle *v) : Window()
    00801   {
    00802     this->vehicle = v;
    00803
    00804     this->CreateNestedTree(desc);
    00805     this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
    00806     this->FinishInitNested(desc, v->index);
    00807     if (v->owner == _local_company) {
    00808       this->DisableWidget(WID_O_EMPTY);
    00809     }
    00810
    00811     this->selected_order = -1;
    00812     this->order_over = INVALID_VEH_ORDER_ID;
    00813     this->owner = v->owner;
    00814
    00815     this->UpdateAutoRefitState();
    00816
    00817     if (_settings_client.gui.quick_goto && v->owner == _local_company) {
    00818       /* If there are less than 2 station, make Go To active. */
    00819       int station_orders = 0;
    00820       const Order *order;
    00821       FOR_VEHICLE_ORDERS(v, order) {
    00822         if (order->IsType(OT_GOTO_STATION)) station_orders++;
    00823       }
    00824
    00825       if (station_orders < 2) this->OrderClick_Goto(0);
    00826     }
    00827     this->OnInvalidateData(VIWD_MODIFY_ORDERS);
    00828   }
    00829
    00830   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00831   {
    00832     switch (widget) {
    00833       case WID_O_ORDER_LIST:
    00834         resize->height = FONT_HEIGHT_NORMAL;
    00835         size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
    00836         break;
    00837
    00838       case WID_O_COND_VARIABLE: {
    00839         Dimension d = {0, 0};
    00840         for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
    00841           d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
    00842         }
    00843         d.width += padding.width;
    00844         d.height += padding.height;
    00845         *size = maxdim(*size, d);
    00846         break;
    00847       }
    00848
    00849       case WID_O_COND_COMPARATOR: {
    00850         Dimension d = {0, 0};
    00851         for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
    00852           d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
    00853         }
    00854         d.width += padding.width;
    00855         d.height += padding.height;
    00856         *size = maxdim(*size, d);
    00857         break;
    00858       }
    00859     }
    00860   }
    00861
    00867   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00868   {
    00869     VehicleOrderID from = INVALID_VEH_ORDER_ID;
    00870     VehicleOrderID to   = INVALID_VEH_ORDER_ID;
    00871
    00872     switch (data) {
    00873       case VIWD_AUTOREPLACE:
    00874         /* Autoreplace replaced the vehicle */
    00875         this->vehicle = Vehicle::Get(this->window_number);
    00876         /* FALL THROUGH */
    00877
    00878       case VIWD_CONSIST_CHANGED:
    00879         /* Vehicle composition was changed. */
    00880         this->UpdateAutoRefitState();
    00881         break;
    00882
    00883       case VIWD_REMOVE_ALL_ORDERS:
    00884         /* Removed / replaced all orders (after deleting / sharing) */
    00885         if (this->selected_order == -1) break;
    00886
    00887         this->DeleteChildWindows();
    00888         HideDropDownMenu(this);
    00889         this->selected_order = -1;
    00890         break;
    00891
    00892       case VIWD_MODIFY_ORDERS:
    00893         /* Some other order changes */
    00894         break;
    00895
    00896       default:
    00897         if (data < 0) break;
    00898
    00899         if (gui_scope) break; // only do this once; from command scope
    00900         from = GB(data, 0, 8);
    00901         to   = GB(data, 8, 8);
    00902         /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
    00903          * the order is being created / removed */
    00904         if (this->selected_order == -1) break;
    00905
    00906         if (from == to) break; // no need to change anything
    00907
    00908         if (from != this->selected_order) {
    00909           /* Moving from preceding order? */
    00910           this->selected_order -= (int)(from <= this->selected_order);
    00911           /* Moving to   preceding order? */
    00912           this->selected_order += (int)(to   <= this->selected_order);
    00913           break;
    00914         }
    00915
    00916         /* Now we are modifying the selected order */
    00917         if (to == INVALID_VEH_ORDER_ID) {
    00918           /* Deleting selected order */
    00919           this->DeleteChildWindows();
    00920           HideDropDownMenu(this);
    00921           this->selected_order = -1;
    00922           break;
    00923         }
    00924
    00925         /* Moving selected order */
    00926         this->selected_order = to;
    00927         break;
    00928     }
    00929
    00930     this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
    00931     if (gui_scope) this->UpdateButtonState();
    00932
    00933     /* Scroll to the new order. */
    00934     if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
    00935       this->vscroll->ScrollTowards(to);
    00936     }
    00937   }
    00938
    00939   void UpdateButtonState()
    00940   {
    00941     if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
    00942
    00943     bool shared_orders = this->vehicle->IsOrderListShared();
    00944     VehicleOrderID sel = this->OrderGetSel();
    00945     const Order *order = this->vehicle->GetOrder(sel);
    00946
    00947     /* Second row. */
    00948     /* skip */
    00949     this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
    00950
    00951     /* delete / stop sharing */
    00952     NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
    00953     if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
    00954       /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
    00955       delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_STOP_SHARING);
    00956     } else {
    00957       /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
    00958       delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
    00959       this->SetWidgetDisabledState(WID_O_DELETE,
    00960         (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
    00961
    00962       /* Set the tooltip of the 'delete' button depending on whether the
    00963        * 'End of Orders' order or a regular order is selected. */
    00964       NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
    00965       if (this->selected_order == this->vehicle->GetNumOrders()) {
    00966         nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
    00967       } else {
    00968         nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
    00969       }
    00970     }
    00971
    00972     /* First row. */
    00973     this->RaiseWidget(WID_O_FULL_LOAD);
    00974     this->RaiseWidget(WID_O_UNLOAD);
    00975     this->RaiseWidget(WID_O_SERVICE);
    00976
    00977     /* Selection widgets. */
    00978     /* Train or road vehicle. */
    00979     NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
    00980     NWidgetStacked *left_sel      = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
    00981     NWidgetStacked *middle_sel    = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
    00982     NWidgetStacked *right_sel     = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
    00983     /* Ship or airplane. */
    00984     NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
    00985     assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
    00986
    00987
    00988     if (order == NULL) {
    00989       if (row_sel != NULL) {
    00990         row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    00991       } else {
    00992         train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    00993         left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    00994         middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    00995         right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    00996         this->DisableWidget(WID_O_NON_STOP);
    00997         this->RaiseWidget(WID_O_NON_STOP);
    00998       }
    00999       this->DisableWidget(WID_O_FULL_LOAD);
    01000       this->DisableWidget(WID_O_UNLOAD);
    01001       this->DisableWidget(WID_O_REFIT_DROPDOWN);
    01002     } else {
    01003       this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
    01004       this->SetWidgetDisabledState(WID_O_UNLOAD,    (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
    01005
    01006       switch (order->GetType()) {
    01007         case OT_GOTO_STATION:
    01008           if (row_sel != NULL) {
    01009             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01010           } else {
    01011             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01012             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01013             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01014             right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
    01015             this->EnableWidget(WID_O_NON_STOP);
    01016             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01017           }
    01018           this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
    01019           this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
    01020
    01021           /* Can only do refitting when stopping at the destination and loading cargo.
    01022            * Also enable the button if a refit is already set to allow clearing it. */
    01023           this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
    01024               order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
    01025               ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
    01026
    01027           break;
    01028
    01029         case OT_GOTO_WAYPOINT:
    01030           if (row_sel != NULL) {
    01031             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01032           } else {
    01033             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01034             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01035             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01036             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01037             this->EnableWidget(WID_O_NON_STOP);
    01038             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01039           }
    01040           this->DisableWidget(WID_O_FULL_LOAD);
    01041           this->DisableWidget(WID_O_UNLOAD);
    01042           this->DisableWidget(WID_O_REFIT_DROPDOWN);
    01043           break;
    01044
    01045         case OT_GOTO_DEPOT:
    01046           if (row_sel != NULL) {
    01047             row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
    01048           } else {
    01049             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01050             left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
    01051             middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
    01052             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01053             this->EnableWidget(WID_O_NON_STOP);
    01054             this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
    01055           }
    01056           /* Disable refit button if the order is no 'always go' order.
    01057            * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
    01058           this->SetWidgetDisabledState(WID_O_REFIT,
    01059               (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
    01060               (!this->can_do_refit && !order->IsRefit()));
    01061           this->SetWidgetLoweredState(WID_O_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
    01062           break;
    01063
    01064         case OT_CONDITIONAL: {
    01065           if (row_sel != NULL) {
    01066             row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
    01067           } else {
    01068             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
    01069           }
    01070           OrderConditionVariable ocv = order->GetConditionVariable();
    01071           /* Set the strings for the dropdown boxes. */
    01072           this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data   = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + (order == NULL ? 0 : ocv);
    01073           this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
    01074           this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
    01075           this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
    01076           break;
    01077         }
    01078
    01079         default: // every other order
    01080           if (row_sel != NULL) {
    01081             row_sel->SetDisplayedPlane(DP_ROW_LOAD);
    01082           } else {
    01083             train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
    01084             left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
    01085             middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
    01086             right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
    01087             this->DisableWidget(WID_O_NON_STOP);
    01088           }
    01089           this->DisableWidget(WID_O_FULL_LOAD);
    01090           this->DisableWidget(WID_O_UNLOAD);
    01091           this->DisableWidget(WID_O_REFIT_DROPDOWN);
    01092           break;
    01093       }
    01094     }
    01095
    01096     /* Disable list of vehicles with the same shared orders if there is no list */
    01097     this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
    01098
    01099     this->SetDirty();
    01100   }
    01101
    01102   virtual void OnPaint()
    01103   {
    01104     if (this->vehicle->owner != _local_company) this->selected_order = -1; // Disable selection any selected row at a competitor order window.
    01105     this->DrawWidgets();
    01106   }
    01107
    01108   virtual void DrawWidget(const Rect &r, int widget) const
    01109   {
    01110     if (widget != WID_O_ORDER_LIST) return;
    01111
    01112     bool rtl = _current_text_dir == TD_RTL;
    01113     SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
    01114     int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
    01115     int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
    01116
    01117     int y = r.top + WD_FRAMERECT_TOP;
    01118     int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
    01119
    01120     int i = this->vscroll->GetPosition();
    01121     const Order *order = this->vehicle->GetOrder(i);
    01122     /* First draw the highlighting underground if it exists. */
    01123     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01124       while (order != NULL) {
    01125         /* Don't draw anything if it extends past the end of the window. */
    01126         if (!this->vscroll->IsVisible(i)) break;
    01127
    01128         if (i != this->selected_order && i == this->order_over) {
    01129           /* Highlight dragged order destination. */
    01130           int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
    01131           int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
    01132           top = max(top - 3, r.top + WD_FRAMERECT_TOP);
    01133           GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
    01134           break;
    01135         }
    01136         y += line_height;
    01137
    01138         i++;
    01139         order = order->next;
    01140       }
    01141
    01142       /* Reset counters for drawing the orders. */
    01143       y = r.top + WD_FRAMERECT_TOP;
    01144       i = this->vscroll->GetPosition();
    01145       order = this->vehicle->GetOrder(i);
    01146     }
    01147
    01148     /* Draw the orders. */
    01149     while (order != NULL) {
    01150       /* Don't draw anything if it extends past the end of the window. */
    01151       if (!this->vscroll->IsVisible(i)) break;
    01152
    01153       DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
    01154       y += line_height;
    01155
    01156       i++;
    01157       order = order->next;
    01158     }
    01159
    01160     if (this->vscroll->IsVisible(i)) {
    01161       StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
    01162       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);
    01163     }
    01164   }
    01165
    01166   virtual void SetStringParameters(int widget) const
    01167   {
    01168     switch (widget) {
    01169       case WID_O_COND_VALUE: {
    01170         VehicleOrderID sel = this->OrderGetSel();
    01171         const Order *order = this->vehicle->GetOrder(sel);
    01172
    01173         if (order != NULL && order->IsType(OT_CONDITIONAL)) {
    01174           uint value = order->GetConditionValue();
    01175           if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01176           SetDParam(0, value);
    01177         }
    01178         break;
    01179       }
    01180
    01181       case WID_O_CAPTION:
    01182         SetDParam(0, this->vehicle->index);
    01183         break;
    01184     }
    01185   }
    01186
    01187   virtual void OnClick(Point pt, int widget, int click_count)
    01188   {
    01189     switch (widget) {
    01190       case WID_O_ORDER_LIST: {
    01191         if (this->goto_type == OPOS_CONDITIONAL) {
    01192           this->goto_type = OPOS_GOTO;
    01193           VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
    01194           if (order_id != INVALID_VEH_ORDER_ID) {
    01195             Order order;
    01196             order.next = NULL;
    01197             order.index = 0;
    01198             order.MakeConditional(order_id);
    01199
    01200             DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
    01201           }
    01202           ResetObjectToPlace();
    01203           break;
    01204         }
    01205
    01206         VehicleOrderID sel = this->GetOrderFromPt(pt.y);
    01207
    01208         if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
    01209           TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
    01210           if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
    01211           return;
    01212         }
    01213
    01214         /* This order won't be selected any more, close all child windows and dropdowns */
    01215         this->DeleteChildWindows();
    01216         HideDropDownMenu(this);
    01217
    01218         if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
    01219           /* Deselect clicked order */
    01220           this->selected_order = -1;
    01221         } else if (sel == this->selected_order) {
    01222           if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
    01223             DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
    01224                 MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
    01225                 CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01226           }
    01227         } else {
    01228           /* Select clicked order */
    01229           this->selected_order = sel;
    01230
    01231           if (this->vehicle->owner == _local_company) {
    01232             /* Activate drag and drop */
    01233             SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
    01234           }
    01235         }
    01236
    01237         this->UpdateButtonState();
    01238         break;
    01239       }
    01240
    01241       case WID_O_SKIP:
    01242         this->OrderClick_Skip(0);
    01243         break;
    01244
    01245       case WID_O_DELETE:
    01246         this->OrderClick_Delete(0);
    01247         break;
    01248
    01249       case WID_O_STOP_SHARING:
    01250         this->OrderClick_StopSharing(0);
    01251         break;
    01252
    01253       case WID_O_NON_STOP:
    01254         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01255           this->OrderClick_Nonstop(-1);
    01256         } else {
    01257           const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01258           ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
    01259                           o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
    01260         }
    01261         break;
    01262
    01263       case WID_O_GOTO:
    01264         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01265           this->OrderClick_Goto(0);
    01266         } else {
    01267           ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, 0, WID_O_GOTO, 0, 0);
    01268         }
    01269         break;
    01270
    01271       case WID_O_FULL_LOAD:
    01272         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01273           this->OrderClick_FullLoad(-1);
    01274         } else {
    01275           ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
    01276         }
    01277         break;
    01278
    01279       case WID_O_UNLOAD:
    01280         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01281           this->OrderClick_Unload(-1);
    01282         } else {
    01283           ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
    01284         }
    01285         break;
    01286
    01287       case WID_O_REFIT:
    01288         this->OrderClick_Refit(0, false);
    01289         break;
    01290
    01291       case WID_O_SERVICE:
    01292         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01293           this->OrderClick_Service(-1);
    01294         } else {
    01295           ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
    01296         }
    01297         break;
    01298
    01299       case WID_O_REFIT_DROPDOWN:
    01300         if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
    01301           this->OrderClick_Refit(0, true);
    01302         } else {
    01303           ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
    01304         }
    01305         break;
    01306
    01307       case WID_O_TIMETABLE_VIEW:
    01308         ShowTimetableWindow(this->vehicle);
    01309         break;
    01310
    01311       case WID_O_COND_VARIABLE: {
    01312         DropDownList *list = new DropDownList();
    01313         for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
    01314           list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false));
    01315         }
    01316         ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
    01317         break;
    01318       }
    01319
    01320       case WID_O_COND_COMPARATOR: {
    01321         const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
    01322         ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
    01323         break;
    01324       }
    01325
    01326       case WID_O_COND_VALUE: {
    01327         const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
    01328         uint value = order->GetConditionValue();
    01329         if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
    01330         SetDParam(0, value);
    01331         ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
    01332         break;
    01333       }
    01334
    01335       case WID_O_SHARED_ORDER_LIST:
    01336         ShowVehicleListWindow(this->vehicle);
    01337         break;
    01338     }
    01339   }
    01340
    01341   virtual void OnQueryTextFinished(char *str)
    01342   {
    01343     if (!StrEmpty(str)) {
    01344       VehicleOrderID sel = this->OrderGetSel();
    01345       uint value = atoi(str);
    01346
    01347       switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
    01348         case OCV_MAX_SPEED:
    01349           value = ConvertDisplaySpeedToSpeed(value);
    01350           break;
    01351
    01352         case OCV_RELIABILITY:
    01353         case OCV_LOAD_PERCENTAGE:
    01354           value = Clamp(value, 0, 100);
    01355           break;
    01356
    01357         default:
    01358           break;
    01359       }
    01360       DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01361     }
    01362   }
    01363
    01364   virtual void OnDropdownSelect(int widget, int index)
    01365   {
    01366     switch (widget) {
    01367       case WID_O_NON_STOP:
    01368         this->OrderClick_Nonstop(index);
    01369         break;
    01370
    01371       case WID_O_FULL_LOAD:
    01372         this->OrderClick_FullLoad(index);
    01373         break;
    01374
    01375       case WID_O_UNLOAD:
    01376         this->OrderClick_Unload(index);
    01377         break;
    01378
    01379       case WID_O_GOTO:
    01380         switch (index) {
    01381           case 0: this->OrderClick_Goto(0); break;
    01382           case 1: this->OrderClick_NearestDepot(0); break;
    01383           case 2: this->OrderClick_Conditional(0); break;
    01384           case 3: this->OrderClick_Share(0); break;
    01385           default: NOT_REACHED();
    01386         }
    01387         break;
    01388
    01389       case WID_O_SERVICE:
    01390         this->OrderClick_Service(index);
    01391         break;
    01392
    01393       case WID_O_REFIT_DROPDOWN:
    01394         this->OrderClick_Refit(index, true);
    01395         break;
    01396
    01397       case WID_O_COND_VARIABLE:
    01398         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VARIABLE | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01399         break;
    01400
    01401       case WID_O_COND_COMPARATOR:
    01402         DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4,  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
    01403         break;
    01404     }
    01405   }
    01406
    01407   virtual void OnDragDrop(Point pt, int widget)
    01408   {
    01409     switch (widget) {
    01410       case WID_O_ORDER_LIST: {
    01411         VehicleOrderID from_order = this->OrderGetSel();
    01412         VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
    01413
    01414         if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) &&
    01415             DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
    01416           this->selected_order = -1;
    01417           this->UpdateButtonState();
    01418         }
    01419         break;
    01420       }
    01421
    01422       case WID_O_DELETE:
    01423         this->OrderClick_Delete(0);
    01424         break;
    01425
    01426       case WID_O_STOP_SHARING:
    01427         this->OrderClick_StopSharing(0);
    01428         break;
    01429     }
    01430
    01431     ResetObjectToPlace();
    01432
    01433     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01434       /* End of drag-and-drop, hide dragged order destination highlight. */
    01435       this->order_over = INVALID_VEH_ORDER_ID;
    01436       this->SetWidgetDirty(WID_O_ORDER_LIST);
    01437     }
    01438   }
    01439
    01440   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    01441   {
    01442     if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
    01443
    01444     return CheckHotkeyMatch<OrdersWindow>(order_hotkeys, keycode, this) != -1 ? ES_HANDLED : ES_NOT_HANDLED;
    01445   }
    01446
    01447   virtual void OnPlaceObject(Point pt, TileIndex tile)
    01448   {
    01449     if (this->goto_type == OPOS_GOTO) {
    01450       const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
    01451       if (cmd.IsType(OT_NOTHING)) return;
    01452
    01453       if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
    01454         /* With quick goto the Go To button stays active */
    01455         if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
    01456       }
    01457     }
    01458   }
    01459
    01460   virtual bool OnVehicleSelect(const Vehicle *v)
    01461   {
    01462     /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
    01463      * We disallow copying orders of other vehicles if we already have at least one order entry
    01464      * ourself as it easily copies orders of vehicles within a station when we mean the station.
    01465      * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
    01466      * TODO: give a warning message */
    01467     bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
    01468     if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
    01469
    01470     if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
    01471         share_order ? CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST))) {
    01472       this->selected_order = -1;
    01473       ResetObjectToPlace();
    01474     }
    01475     return true;
    01476   }
    01477
    01478   virtual void OnPlaceObjectAbort()
    01479   {
    01480     this->RaiseWidget(WID_O_GOTO);
    01481     this->SetWidgetDirty(WID_O_GOTO);
    01482
    01483     /* Remove drag highlighting if it exists. */
    01484     if (this->order_over != INVALID_VEH_ORDER_ID) {
    01485       this->order_over = INVALID_VEH_ORDER_ID;
    01486       this->SetWidgetDirty(WID_O_ORDER_LIST);
    01487     }
    01488   }
    01489
    01490   virtual void OnMouseDrag(Point pt, int widget)
    01491   {
    01492     if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
    01493       /* An order is dragged.. */
    01494       VehicleOrderID from_order = this->OrderGetSel();
    01495       VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
    01496       uint num_orders = this->vehicle->GetNumOrders();
    01497
    01498       if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
    01499         if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
    01500           this->order_over = to_order;
    01501           this->SetWidgetDirty(widget);
    01502         } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
    01503           this->order_over = INVALID_VEH_ORDER_ID;
    01504           this->SetWidgetDirty(widget);
    01505         }
    01506       }
    01507     }
    01508   }
    01509
    01510   virtual void OnResize()
    01511   {
    01512     /* Update the scroll bar */
    01513     this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
    01514   }
    01515
    01516   static Hotkey<OrdersWindow> order_hotkeys[];
    01517 };
    01518
    01519 Hotkey<OrdersWindow> OrdersWindow::order_hotkeys[] = {
    01520   Hotkey<OrdersWindow>('D', "skip", 0, &OrdersWindow::OrderClick_Skip),
    01521   Hotkey<OrdersWindow>('F', "delete", 0, &OrdersWindow::OrderClick_Delete),
    01522   Hotkey<OrdersWindow>('G', "goto", 0, &OrdersWindow::OrderClick_Goto),
    01523   Hotkey<OrdersWindow>('H', "nonstop", 0, &OrdersWindow::OrderClick_Nonstop),
    01524   Hotkey<OrdersWindow>('J', "fullload", 0, &OrdersWindow::OrderClick_FullLoad),
    01525   Hotkey<OrdersWindow>('K', "unload", 0, &OrdersWindow::OrderClick_Unload),
    01526   Hotkey<OrdersWindow>((uint16)0, "nearest_depot", 0, &OrdersWindow::OrderClick_NearestDepot),
    01527   Hotkey<OrdersWindow>((uint16)0, "always_service", 0, &OrdersWindow::OrderClick_Service),
    01528   Hotkey<OrdersWindow>((uint16)0, "transfer", 0, &OrdersWindow::OrderHotkey_Transfer),
    01529   Hotkey<OrdersWindow>((uint16)0, "no_unload", 0, &OrdersWindow::OrderHotkey_NoUnload),
    01530   Hotkey<OrdersWindow>((uint16)0, "no_load", 0, &OrdersWindow::OrderHotkey_NoLoad),
    01531   HOTKEY_LIST_END(OrdersWindow)
    01532 };
    01533 Hotkey<OrdersWindow> *_order_hotkeys = OrdersWindow::order_hotkeys;
    01534
    01536 static const NWidgetPart _nested_orders_train_widgets[] = {
    01537   NWidget(NWID_HORIZONTAL),
    01538     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01539     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01540     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01541     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01542     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01543   EndContainer(),
    01544   NWidget(NWID_HORIZONTAL),
    01545     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01546     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01547   EndContainer(),
    01548
    01549   /* First button row. */
    01550   NWidget(NWID_HORIZONTAL),
    01551     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW_GROUNDVEHICLE),
    01552       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01553         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
    01554                               SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
    01555         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
    01556           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
    01557                               SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01558           NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
    01559                               SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01560         EndContainer(),
    01561         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
    01562           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
    01563                               SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01564           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
    01565                               SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01566         EndContainer(),
    01567         NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
    01568           NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
    01569                               SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01570           NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
    01571                               SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
    01572         EndContainer(),
    01573       EndContainer(),
    01574       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01575         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01576                               SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01577         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01578                               SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01579         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01580                               SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01581       EndContainer(),
    01582     EndContainer(),
    01583     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01584   EndContainer(),
    01585
    01586   /* Second button row. */
    01587   NWidget(NWID_HORIZONTAL),
    01588     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01589       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01590                           SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01591       NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
    01592         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01593                             SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01594         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
    01595                             SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
    01596       EndContainer(),
    01597       NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01598                           SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01599     EndContainer(),
    01600     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01601   EndContainer(),
    01602 };
    01603
    01604 static const WindowDesc _orders_train_desc(
    01605   WDP_AUTO, 384, 100,
    01606   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01607   WDF_CONSTRUCTION,
    01608   _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets)
    01609 );
    01610
    01612 static const NWidgetPart _nested_orders_widgets[] = {
    01613   NWidget(NWID_HORIZONTAL),
    01614     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01615     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01616     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01617     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01618     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01619   EndContainer(),
    01620   NWidget(NWID_HORIZONTAL),
    01621     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01622     NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01623   EndContainer(),
    01624
    01625   /* First button row. */
    01626   NWidget(NWID_HORIZONTAL),
    01627     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
    01628       /* Load + unload + refit buttons. */
    01629       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01630         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01631                           SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
    01632         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
    01633                           SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
    01634         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
    01635                           SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
    01636       EndContainer(),
    01637       /* Refit + service buttons. */
    01638       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01639         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
    01640                           SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
    01641         NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
    01642                           SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
    01643       EndContainer(),
    01644
    01645       /* Buttons for setting a condition. */
    01646       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
    01647         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
    01648                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
    01649         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
    01650                           SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
    01651         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
    01652                           SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
    01653       EndContainer(),
    01654     EndContainer(),
    01655
    01656     NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
    01657   EndContainer(),
    01658
    01659   /* Second button row. */
    01660   NWidget(NWID_HORIZONTAL),
    01661     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
    01662                       SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
    01663     NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_BOTTOM_MIDDLE),
    01664       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
    01665                           SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
    01666       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
    01667                           SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
    01668     EndContainer(),
    01669     NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
    01670                       SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
    01671     NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01672   EndContainer(),
    01673 };
    01674
    01675 static const WindowDesc _orders_desc(
    01676   WDP_AUTO, 384, 100,
    01677   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01678   WDF_CONSTRUCTION,
    01679   _nested_orders_widgets, lengthof(_nested_orders_widgets)
    01680 );
    01681
    01683 static const NWidgetPart _nested_other_orders_widgets[] = {
    01684   NWidget(NWID_HORIZONTAL),
    01685     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
    01686     NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01687     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
    01688     NWidget(WWT_SHADEBOX, COLOUR_GREY),
    01689     NWidget(WWT_STICKYBOX, COLOUR_GREY),
    01690   EndContainer(),
    01691   NWidget(NWID_HORIZONTAL),
    01692     NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
    01693     NWidget(NWID_VERTICAL),
    01694       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
    01695       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
    01696     EndContainer(),
    01697   EndContainer(),
    01698 };
    01699
    01700 static const WindowDesc _other_orders_desc(
    01701   WDP_AUTO, 384, 86,
    01702   WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
    01703   WDF_CONSTRUCTION,
    01704   _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets)
    01705 );
    01706
    01707 void ShowOrdersWindow(const Vehicle *v)
    01708 {
    01709   DeleteWindowById(WC_VEHICLE_DETAILS, v->index, false);
    01710   DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
    01711   if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
    01712
    01713   if (v->owner != _local_company) {
    01714     new OrdersWindow(&_other_orders_desc, v);
    01715   } else {
    01716     new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
    01717   }
    01718 }