OpenTTD
order_gui.cpp
Go to the documentation of this file.
1 /* $Id: order_gui.cpp 27425 2015-10-30 17:23:16Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
16 #include "roadveh.h"
17 #include "timetable.h"
18 #include "strings_func.h"
19 #include "company_func.h"
20 #include "widgets/dropdown_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "textbuf_gui.h"
23 #include "string_func.h"
24 #include "tilehighlight_func.h"
25 #include "network/network.h"
26 #include "station_base.h"
27 #include "waypoint_base.h"
28 #include "core/geometry_func.hpp"
29 #include "hotkeys.h"
30 #include "aircraft.h"
31 #include "engine_func.h"
32 
33 #include "widgets/order_widget.h"
34 
35 #include "safeguards.h"
36 
37 
39 static const StringID _station_load_types[][5][5] = {
40  {
41  /* No refitting. */
42  {
43  STR_EMPTY,
45  STR_ORDER_FULL_LOAD,
46  STR_ORDER_FULL_LOAD_ANY,
47  STR_ORDER_NO_LOAD,
48  }, {
49  STR_ORDER_UNLOAD,
51  STR_ORDER_UNLOAD_FULL_LOAD,
52  STR_ORDER_UNLOAD_FULL_LOAD_ANY,
53  STR_ORDER_UNLOAD_NO_LOAD,
54  }, {
55  STR_ORDER_TRANSFER,
57  STR_ORDER_TRANSFER_FULL_LOAD,
58  STR_ORDER_TRANSFER_FULL_LOAD_ANY,
59  STR_ORDER_TRANSFER_NO_LOAD,
60  }, {
61  /* Unload and transfer do not work together. */
66  }, {
67  STR_ORDER_NO_UNLOAD,
69  STR_ORDER_NO_UNLOAD_FULL_LOAD,
70  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
71  STR_ORDER_NO_UNLOAD_NO_LOAD,
72  }
73  }, {
74  /* With auto-refitting. No loading and auto-refitting do not work together. */
75  {
76  STR_ORDER_AUTO_REFIT,
78  STR_ORDER_FULL_LOAD_REFIT,
79  STR_ORDER_FULL_LOAD_ANY_REFIT,
81  }, {
82  STR_ORDER_UNLOAD_REFIT,
84  STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
85  STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
87  }, {
88  STR_ORDER_TRANSFER_REFIT,
90  STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
91  STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
93  }, {
94  /* Unload and transfer do not work together. */
99  }, {
100  STR_ORDER_NO_UNLOAD_REFIT,
102  STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
103  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
105  }
106  }
107 };
108 
109 static const StringID _order_non_stop_drowdown[] = {
110  STR_ORDER_GO_TO,
111  STR_ORDER_GO_NON_STOP_TO,
112  STR_ORDER_GO_VIA,
113  STR_ORDER_GO_NON_STOP_VIA,
115 };
116 
117 static const StringID _order_full_load_drowdown[] = {
118  STR_ORDER_DROP_LOAD_IF_POSSIBLE,
119  STR_EMPTY,
120  STR_ORDER_DROP_FULL_LOAD_ALL,
121  STR_ORDER_DROP_FULL_LOAD_ANY,
122  STR_ORDER_DROP_NO_LOADING,
124 };
125 
126 static const StringID _order_unload_drowdown[] = {
127  STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
128  STR_ORDER_DROP_UNLOAD,
129  STR_ORDER_DROP_TRANSFER,
130  STR_EMPTY,
131  STR_ORDER_DROP_NO_UNLOADING,
133 };
134 
135 static const StringID _order_goto_dropdown[] = {
136  STR_ORDER_GO_TO,
137  STR_ORDER_GO_TO_NEAREST_DEPOT,
138  STR_ORDER_CONDITIONAL,
139  STR_ORDER_SHARE,
141 };
142 
143 static const StringID _order_goto_dropdown_aircraft[] = {
144  STR_ORDER_GO_TO,
145  STR_ORDER_GO_TO_NEAREST_HANGAR,
146  STR_ORDER_CONDITIONAL,
147  STR_ORDER_SHARE,
149 };
150 
156  OCV_AGE,
160 };
161 
162 static const StringID _order_conditional_condition[] = {
163  STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
164  STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
165  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
166  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
167  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
168  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
169  STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
170  STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
172 };
173 
174 extern uint ConvertSpeedToDisplaySpeed(uint speed);
175 extern uint ConvertDisplaySpeedToSpeed(uint speed);
176 
177 static const StringID _order_depot_action_dropdown[] = {
178  STR_ORDER_DROP_GO_ALWAYS_DEPOT,
179  STR_ORDER_DROP_SERVICE_DEPOT,
180  STR_ORDER_DROP_HALT_DEPOT,
182 };
183 
184 static int DepotActionStringIndex(const Order *order)
185 {
186  if (order->GetDepotActionType() & ODATFB_HALT) {
187  return DA_STOP;
188  } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
189  return DA_SERVICE;
190  } else {
191  return DA_ALWAYS_GO;
192  }
193 }
194 
195 static const StringID _order_refit_action_dropdown[] = {
196  STR_ORDER_DROP_REFIT_AUTO,
197  STR_ORDER_DROP_REFIT_AUTO_ANY,
199 };
200 
213 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
214 {
215  bool rtl = _current_text_dir == TD_RTL;
216 
217  SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
218  Dimension sprite_size = GetSpriteSize(sprite);
219  if (v->cur_real_order_index == order_index) {
220  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
221  DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
222  } else if (v->cur_implicit_order_index == order_index) {
223  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
224  }
225 
226  TextColour colour = TC_BLACK;
227  if (order->IsType(OT_IMPLICIT)) {
228  colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
229  } else if (selected) {
230  colour = TC_WHITE;
231  }
232 
233  SetDParam(0, order_index + 1);
234  DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
235 
236  SetDParam(5, STR_EMPTY);
237  SetDParam(8, STR_EMPTY);
238 
239  /* Check range for aircraft. */
240  if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
241  const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
242  if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
243  }
244 
245  switch (order->GetType()) {
246  case OT_DUMMY:
247  SetDParam(0, STR_INVALID_ORDER);
248  SetDParam(1, order->GetDestination());
249  break;
250 
251  case OT_IMPLICIT:
252  SetDParam(0, STR_ORDER_GO_TO_STATION);
253  SetDParam(1, STR_ORDER_GO_TO);
254  SetDParam(2, order->GetDestination());
255  SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
256  break;
257 
258  case OT_GOTO_STATION: {
259  OrderLoadFlags load = order->GetLoadType();
260  OrderUnloadFlags unload = order->GetUnloadType();
261 
262  SetDParam(0, STR_ORDER_GO_TO_STATION);
263  SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
264  SetDParam(2, order->GetDestination());
265 
266  if (timetable) {
267  SetDParam(3, STR_EMPTY);
268 
269  if (order->GetWaitTime() > 0) {
270  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
271  SetTimetableParams(6, 7, order->GetWaitTime());
272  }
273  } else {
274  SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
275  if (order->IsRefit()) {
276  SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
277  }
278  if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
279  SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
280  }
281  }
282  break;
283  }
284 
285  case OT_GOTO_DEPOT:
286  if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
287  SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
288  if (v->type == VEH_AIRCRAFT) {
289  SetDParam(2, STR_ORDER_NEAREST_HANGAR);
290  SetDParam(3, STR_EMPTY);
291  } else {
292  SetDParam(2, STR_ORDER_NEAREST_DEPOT);
293  SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
294  }
295  } else {
296  SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
297  SetDParam(2, v->type);
298  SetDParam(3, order->GetDestination());
299  }
300 
301  if (order->GetDepotOrderType() & ODTFB_SERVICE) {
302  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
303  } else {
304  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
305  }
306 
307  if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
308  SetDParam(5, STR_ORDER_STOP_ORDER);
309  }
310 
311  if (!timetable && order->IsRefit()) {
312  SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
313  SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
314  }
315  break;
316 
317  case OT_GOTO_WAYPOINT:
318  SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
319  SetDParam(1, order->GetDestination());
320  break;
321 
322  case OT_CONDITIONAL:
323  SetDParam(1, order->GetConditionSkipToOrder() + 1);
324  if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
325  SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
326  } else {
328  SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
329  SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
330  SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
331 
332  uint value = order->GetConditionValue();
333  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
334  SetDParam(4, value);
335  }
336 
337  if (timetable && order->GetWaitTime() > 0) {
338  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
339  SetTimetableParams(6, 7, order->GetWaitTime());
340  } else {
341  SetDParam(5, STR_EMPTY);
342  }
343  break;
344 
345  default: NOT_REACHED();
346  }
347 
348  DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
349 }
350 
358 {
359  /* Hack-ish; unpack order 0, so everything gets initialised with either zero
360  * or a suitable default value for the variable. Then also override the index
361  * as it is not coming from a pool, so would be initialised. */
362  Order order(0);
363  order.index = 0;
364 
365  /* check depot first */
366  if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
367  order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
370 
372 
373  return order;
374  }
375 
376  /* check rail waypoint */
377  if (IsRailWaypointTile(tile) &&
378  v->type == VEH_TRAIN &&
379  IsTileOwner(tile, _local_company)) {
380  order.MakeGoToWaypoint(GetStationIndex(tile));
382  return order;
383  }
384 
385  /* check buoy (no ownership) */
386  if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
387  order.MakeGoToWaypoint(GetStationIndex(tile));
388  return order;
389  }
390 
391  if (IsTileType(tile, MP_STATION)) {
392  StationID st_index = GetStationIndex(tile);
393  const Station *st = Station::Get(st_index);
394 
395  if (st->owner == _local_company || st->owner == OWNER_NONE) {
396  byte facil;
397  (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
398  (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
399  (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
400  (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
401  (facil = FACIL_TRUCK_STOP, 1);
402  if (st->facilities & facil) {
403  order.MakeGoToStation(st_index);
407  return order;
408  }
409  }
410  }
411 
412  /* not found */
413  order.Free();
414  return order;
415 }
416 
418 enum {
419  OHK_SKIP,
420  OHK_DELETE,
421  OHK_GOTO,
422  OHK_NONSTOP,
423  OHK_FULLLOAD,
424  OHK_UNLOAD,
425  OHK_NEAREST_DEPOT,
426  OHK_ALWAYS_SERVICE,
427  OHK_TRANSFER,
428  OHK_NO_UNLOAD,
429  OHK_NO_LOAD,
430 };
431 
472 struct OrdersWindow : public Window {
473 private:
476  OPOS_NONE,
477  OPOS_GOTO,
478  OPOS_CONDITIONAL,
479  OPOS_SHARE,
480  OPOS_END,
481  };
482 
484  enum DisplayPane {
485  /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
488 
489  /* WID_O_SEL_TOP_LEFT */
492 
493  /* WID_O_SEL_TOP_MIDDLE */
496 
497  /* WID_O_SEL_TOP_RIGHT */
500 
501  /* WID_O_SEL_TOP_ROW */
505 
506  /* WID_O_SEL_BOTTOM_MIDDLE */
509  };
510 
511  int selected_order;
513  OrderPlaceObjectState goto_type;
514  const Vehicle *vehicle;
515  Scrollbar *vscroll;
518 
525  {
526  int num = this->selected_order;
527  return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
528  }
529 
539  {
540  NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
541  int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
542 
543  if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
544 
545  sel += this->vscroll->GetPosition();
546 
547  return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
548  }
549 
554  {
555  assert(type > OPOS_NONE && type < OPOS_END);
556 
557  static const HighLightStyle goto_place_style[OPOS_END - 1] = {
558  HT_RECT | HT_VEHICLE, // OPOS_GOTO
559  HT_NONE, // OPOS_CONDITIONAL
560  HT_VEHICLE, // OPOS_SHARE
561  };
562  SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
563  this->goto_type = type;
564  this->SetWidgetDirty(WID_O_GOTO);
565  }
566 
571  void OrderClick_FullLoad(int load_type)
572  {
573  VehicleOrderID sel_ord = this->OrderGetSel();
574  const Order *order = this->vehicle->GetOrder(sel_ord);
575 
576  if (order == NULL || order->GetLoadType() == load_type) return;
577 
578  if (load_type < 0) {
580  }
581  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));
582  }
583 
588  {
590  }
591 
595  void OrderClick_Service(int i)
596  {
597  VehicleOrderID sel_ord = this->OrderGetSel();
598 
599  if (i < 0) {
600  const Order *order = this->vehicle->GetOrder(sel_ord);
601  if (order == NULL) return;
603  }
604  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));
605  }
606 
611  {
612  Order order;
613  order.next = NULL;
614  order.index = 0;
618 
619  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
620  }
621 
625  void OrderClick_Unload(int unload_type)
626  {
627  VehicleOrderID sel_ord = this->OrderGetSel();
628  const Order *order = this->vehicle->GetOrder(sel_ord);
629 
630  if (order == NULL || order->GetUnloadType() == unload_type) return;
631 
632  if (unload_type < 0) {
634  }
635 
636  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));
637 
638  /* Transfer orders with leave empty as default */
639  if (unload_type == OUFB_TRANSFER) {
640  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
642  }
643  }
644 
649  {
651  }
652 
657  {
659  }
660 
665  void OrderClick_Nonstop(int non_stop)
666  {
667  if (!this->vehicle->IsGroundVehicle()) return;
668 
669  VehicleOrderID sel_ord = this->OrderGetSel();
670  const Order *order = this->vehicle->GetOrder(sel_ord);
671 
672  if (order == NULL || order->GetNonStopType() == non_stop) return;
673 
674  /* Keypress if negative, so 'toggle' to the next */
675  if (non_stop < 0) {
677  }
678 
680  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));
681  }
682 
688  {
689  /* Don't skip when there's nothing to skip */
690  if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
691  if (this->vehicle->GetNumOrders() <= 1) return;
692 
693  DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
694  CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
695  }
696 
701  {
702  /* When networking, move one order lower */
703  int selected = this->selected_order + (int)_networking;
704 
705  if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
706  this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
707  this->UpdateButtonState();
708  }
709  }
710 
718  {
719  /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
720  if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
721  /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
722  if (_ctrl_pressed) {
723  this->OrderClick_Delete();
724  return;
725  }
726 
727  /* Get another vehicle that share orders with this vehicle. */
728  Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
729  /* Copy the order list of the other vehicle. */
730  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))) {
731  this->UpdateButtonState();
732  }
733  }
734 
741  void OrderClick_Refit(int i, bool auto_refit)
742  {
743  if (_ctrl_pressed) {
744  /* Cancel refitting */
745  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
746  } else {
747  if (i == 1) { // Auto-refit to available cargo type.
748  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
749  } else {
750  ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
751  }
752  }
753  }
754 
757  {
758  this->can_do_refit = false;
759  this->can_do_autorefit = false;
760  for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
761  if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
762  if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
763  }
764  }
765 
766 public:
767  OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
768  {
769  this->vehicle = v;
770 
771  this->CreateNestedTree();
772  this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
773  this->FinishInitNested(v->index);
774  if (v->owner == _local_company) {
775  this->DisableWidget(WID_O_EMPTY);
776  }
777 
778  this->selected_order = -1;
780  this->goto_type = OPOS_NONE;
781  this->owner = v->owner;
782 
783  this->UpdateAutoRefitState();
784 
786  /* If there are less than 2 station, make Go To active. */
787  int station_orders = 0;
788  const Order *order;
789  FOR_VEHICLE_ORDERS(v, order) {
790  if (order->IsType(OT_GOTO_STATION)) station_orders++;
791  }
792 
793  if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
794  }
796  }
797 
798  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
799  {
800  switch (widget) {
801  case WID_O_ORDER_LIST:
802  resize->height = FONT_HEIGHT_NORMAL;
803  size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
804  break;
805 
806  case WID_O_COND_VARIABLE: {
807  Dimension d = {0, 0};
808  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
809  d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
810  }
811  d.width += padding.width;
812  d.height += padding.height;
813  *size = maxdim(*size, d);
814  break;
815  }
816 
817  case WID_O_COND_COMPARATOR: {
818  Dimension d = {0, 0};
819  for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
820  d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
821  }
822  d.width += padding.width;
823  d.height += padding.height;
824  *size = maxdim(*size, d);
825  break;
826  }
827  }
828  }
829 
835  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
836  {
839 
840  switch (data) {
841  case VIWD_AUTOREPLACE:
842  /* Autoreplace replaced the vehicle */
843  this->vehicle = Vehicle::Get(this->window_number);
844  /* FALL THROUGH */
845 
847  /* Vehicle composition was changed. */
848  this->UpdateAutoRefitState();
849  break;
850 
852  /* Removed / replaced all orders (after deleting / sharing) */
853  if (this->selected_order == -1) break;
854 
855  this->DeleteChildWindows();
856  HideDropDownMenu(this);
857  this->selected_order = -1;
858  break;
859 
860  case VIWD_MODIFY_ORDERS:
861  /* Some other order changes */
862  break;
863 
864  default:
865  if (data < 0) break;
866 
867  if (gui_scope) break; // only do this once; from command scope
868  from = GB(data, 0, 8);
869  to = GB(data, 8, 8);
870  /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
871  * the order is being created / removed */
872  if (this->selected_order == -1) break;
873 
874  if (from == to) break; // no need to change anything
875 
876  if (from != this->selected_order) {
877  /* Moving from preceding order? */
878  this->selected_order -= (int)(from <= this->selected_order);
879  /* Moving to preceding order? */
880  this->selected_order += (int)(to <= this->selected_order);
881  break;
882  }
883 
884  /* Now we are modifying the selected order */
885  if (to == INVALID_VEH_ORDER_ID) {
886  /* Deleting selected order */
887  this->DeleteChildWindows();
888  HideDropDownMenu(this);
889  this->selected_order = -1;
890  break;
891  }
892 
893  /* Moving selected order */
894  this->selected_order = to;
895  break;
896  }
897 
898  this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
899  if (gui_scope) this->UpdateButtonState();
900 
901  /* Scroll to the new order. */
902  if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
903  this->vscroll->ScrollTowards(to);
904  }
905  }
906 
907  void UpdateButtonState()
908  {
909  if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
910 
911  bool shared_orders = this->vehicle->IsOrderListShared();
912  VehicleOrderID sel = this->OrderGetSel();
913  const Order *order = this->vehicle->GetOrder(sel);
914 
915  /* Second row. */
916  /* skip */
918 
919  /* delete / stop sharing */
920  NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
921  if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
922  /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
924  } else {
925  /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
926  delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
928  (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
929 
930  /* Set the tooltip of the 'delete' button depending on whether the
931  * 'End of Orders' order or a regular order is selected. */
932  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
933  if (this->selected_order == this->vehicle->GetNumOrders()) {
934  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
935  } else {
936  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
937  }
938  }
939 
940  /* First row. */
942  this->RaiseWidget(WID_O_UNLOAD);
943  this->RaiseWidget(WID_O_SERVICE);
944 
945  /* Selection widgets. */
946  /* Train or road vehicle. */
947  NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
948  NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
949  NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
950  NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
951  /* Ship or airplane. */
952  NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
953  assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
954 
955 
956  if (order == NULL) {
957  if (row_sel != NULL) {
958  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
959  } else {
961  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
962  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
963  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
966  }
970  } else {
973 
974  switch (order->GetType()) {
975  case OT_GOTO_STATION:
976  if (row_sel != NULL) {
977  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
978  } else {
980  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
981  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
982  right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
985  }
988 
989  /* Can only do refitting when stopping at the destination and loading cargo.
990  * Also enable the button if a refit is already set to allow clearing it. */
993  ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
994 
995  break;
996 
997  case OT_GOTO_WAYPOINT:
998  if (row_sel != NULL) {
999  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1000  } else {
1002  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1003  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1004  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1007  }
1009  this->DisableWidget(WID_O_UNLOAD);
1011  break;
1012 
1013  case OT_GOTO_DEPOT:
1014  if (row_sel != NULL) {
1015  row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1016  } else {
1018  left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1019  middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1020  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1023  }
1024  /* Disable refit button if the order is no 'always go' order.
1025  * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1027  (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1028  (!this->can_do_refit && !order->IsRefit()));
1030  break;
1031 
1032  case OT_CONDITIONAL: {
1033  if (row_sel != NULL) {
1034  row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1035  } else {
1037  }
1039  /* Set the strings for the dropdown boxes. */
1040  this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1041  this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1044  break;
1045  }
1046 
1047  default: // every other order
1048  if (row_sel != NULL) {
1049  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1050  } else {
1052  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1053  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1054  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1056  }
1058  this->DisableWidget(WID_O_UNLOAD);
1060  break;
1061  }
1062  }
1063 
1064  /* Disable list of vehicles with the same shared orders if there is no list */
1065  this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1066 
1067  this->SetDirty();
1068  }
1069 
1070  virtual void OnPaint()
1071  {
1072  if (this->vehicle->owner != _local_company) {
1073  this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1074  } else {
1075  this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1076  }
1077  this->DrawWidgets();
1078  }
1079 
1080  virtual void DrawWidget(const Rect &r, int widget) const
1081  {
1082  if (widget != WID_O_ORDER_LIST) return;
1083 
1084  bool rtl = _current_text_dir == TD_RTL;
1085  SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1086  int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1087  int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1088 
1089  int y = r.top + WD_FRAMERECT_TOP;
1090  int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1091 
1092  int i = this->vscroll->GetPosition();
1093  const Order *order = this->vehicle->GetOrder(i);
1094  /* First draw the highlighting underground if it exists. */
1095  if (this->order_over != INVALID_VEH_ORDER_ID) {
1096  while (order != NULL) {
1097  /* Don't draw anything if it extends past the end of the window. */
1098  if (!this->vscroll->IsVisible(i)) break;
1099 
1100  if (i != this->selected_order && i == this->order_over) {
1101  /* Highlight dragged order destination. */
1102  int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1103  int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1104  top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1105  GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1106  break;
1107  }
1108  y += line_height;
1109 
1110  i++;
1111  order = order->next;
1112  }
1113 
1114  /* Reset counters for drawing the orders. */
1115  y = r.top + WD_FRAMERECT_TOP;
1116  i = this->vscroll->GetPosition();
1117  order = this->vehicle->GetOrder(i);
1118  }
1119 
1120  /* Draw the orders. */
1121  while (order != NULL) {
1122  /* Don't draw anything if it extends past the end of the window. */
1123  if (!this->vscroll->IsVisible(i)) break;
1124 
1125  DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1126  y += line_height;
1127 
1128  i++;
1129  order = order->next;
1130  }
1131 
1132  if (this->vscroll->IsVisible(i)) {
1133  StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1134  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);
1135  }
1136  }
1137 
1138  virtual void SetStringParameters(int widget) const
1139  {
1140  switch (widget) {
1141  case WID_O_COND_VALUE: {
1142  VehicleOrderID sel = this->OrderGetSel();
1143  const Order *order = this->vehicle->GetOrder(sel);
1144 
1145  if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1146  uint value = order->GetConditionValue();
1147  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1148  SetDParam(0, value);
1149  }
1150  break;
1151  }
1152 
1153  case WID_O_CAPTION:
1154  SetDParam(0, this->vehicle->index);
1155  break;
1156  }
1157  }
1158 
1159  virtual void OnClick(Point pt, int widget, int click_count)
1160  {
1161  switch (widget) {
1162  case WID_O_ORDER_LIST: {
1163  if (this->goto_type == OPOS_CONDITIONAL) {
1164  VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1165  if (order_id != INVALID_VEH_ORDER_ID) {
1166  Order order;
1167  order.next = NULL;
1168  order.index = 0;
1169  order.MakeConditional(order_id);
1170 
1171  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1172  }
1174  break;
1175  }
1176 
1177  VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1178 
1179  if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1180  TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1181  if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1182  return;
1183  }
1184 
1185  /* This order won't be selected any more, close all child windows and dropdowns */
1186  this->DeleteChildWindows();
1187  HideDropDownMenu(this);
1188 
1189  if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1190  /* Deselect clicked order */
1191  this->selected_order = -1;
1192  } else if (sel == this->selected_order) {
1193  if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1194  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1195  MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1196  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1197  }
1198  } else {
1199  /* Select clicked order */
1200  this->selected_order = sel;
1201 
1202  if (this->vehicle->owner == _local_company) {
1203  /* Activate drag and drop */
1204  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1205  }
1206  }
1207 
1208  this->UpdateButtonState();
1209  break;
1210  }
1211 
1212  case WID_O_SKIP:
1213  this->OrderClick_Skip();
1214  break;
1215 
1216  case WID_O_DELETE:
1217  this->OrderClick_Delete();
1218  break;
1219 
1220  case WID_O_STOP_SHARING:
1221  this->OrderClick_StopSharing();
1222  break;
1223 
1224  case WID_O_NON_STOP:
1225  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1226  this->OrderClick_Nonstop(-1);
1227  } else {
1228  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1229  ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1230  o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1231  }
1232  break;
1233 
1234  case WID_O_GOTO:
1235  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1236  if (this->goto_type != OPOS_NONE) {
1238  } else {
1239  this->OrderClick_Goto(OPOS_GOTO);
1240  }
1241  } else {
1242  int sel;
1243  switch (this->goto_type) {
1244  case OPOS_NONE: sel = -1; break;
1245  case OPOS_GOTO: sel = 0; break;
1246  case OPOS_CONDITIONAL: sel = 2; break;
1247  case OPOS_SHARE: sel = 3; break;
1248  default: NOT_REACHED();
1249  }
1250  ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1251  }
1252  break;
1253 
1254  case WID_O_FULL_LOAD:
1255  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1256  this->OrderClick_FullLoad(-1);
1257  } else {
1258  ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1259  }
1260  break;
1261 
1262  case WID_O_UNLOAD:
1263  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1264  this->OrderClick_Unload(-1);
1265  } else {
1266  ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1267  }
1268  break;
1269 
1270  case WID_O_REFIT:
1271  this->OrderClick_Refit(0, false);
1272  break;
1273 
1274  case WID_O_SERVICE:
1275  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1276  this->OrderClick_Service(-1);
1277  } else {
1278  ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1279  }
1280  break;
1281 
1282  case WID_O_REFIT_DROPDOWN:
1283  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1284  this->OrderClick_Refit(0, true);
1285  } else {
1286  ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1287  }
1288  break;
1289 
1290  case WID_O_TIMETABLE_VIEW:
1292  break;
1293 
1294  case WID_O_COND_VARIABLE: {
1295  DropDownList *list = new DropDownList();
1296  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1297  *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1298  }
1299  ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1300  break;
1301  }
1302 
1303  case WID_O_COND_COMPARATOR: {
1304  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1305  ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1306  break;
1307  }
1308 
1309  case WID_O_COND_VALUE: {
1310  const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1311  uint value = order->GetConditionValue();
1312  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1313  SetDParam(0, value);
1314  ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1315  break;
1316  }
1317 
1319  ShowVehicleListWindow(this->vehicle);
1320  break;
1321  }
1322  }
1323 
1324  virtual void OnQueryTextFinished(char *str)
1325  {
1326  if (!StrEmpty(str)) {
1327  VehicleOrderID sel = this->OrderGetSel();
1328  uint value = atoi(str);
1329 
1330  switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1331  case OCV_MAX_SPEED:
1332  value = ConvertDisplaySpeedToSpeed(value);
1333  break;
1334 
1335  case OCV_RELIABILITY:
1336  case OCV_LOAD_PERCENTAGE:
1337  value = Clamp(value, 0, 100);
1338  break;
1339 
1340  default:
1341  break;
1342  }
1343  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));
1344  }
1345  }
1346 
1347  virtual void OnDropdownSelect(int widget, int index)
1348  {
1349  switch (widget) {
1350  case WID_O_NON_STOP:
1351  this->OrderClick_Nonstop(index);
1352  break;
1353 
1354  case WID_O_FULL_LOAD:
1355  this->OrderClick_FullLoad(index);
1356  break;
1357 
1358  case WID_O_UNLOAD:
1359  this->OrderClick_Unload(index);
1360  break;
1361 
1362  case WID_O_GOTO:
1363  switch (index) {
1364  case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1365  case 1: this->OrderClick_NearestDepot(); break;
1366  case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1367  case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1368  default: NOT_REACHED();
1369  }
1370  break;
1371 
1372  case WID_O_SERVICE:
1373  this->OrderClick_Service(index);
1374  break;
1375 
1376  case WID_O_REFIT_DROPDOWN:
1377  this->OrderClick_Refit(index, true);
1378  break;
1379 
1380  case WID_O_COND_VARIABLE:
1381  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));
1382  break;
1383 
1384  case WID_O_COND_COMPARATOR:
1385  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));
1386  break;
1387  }
1388  }
1389 
1390  virtual void OnDragDrop(Point pt, int widget)
1391  {
1392  switch (widget) {
1393  case WID_O_ORDER_LIST: {
1394  VehicleOrderID from_order = this->OrderGetSel();
1395  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1396 
1397  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()) &&
1398  DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1399  this->selected_order = -1;
1400  this->UpdateButtonState();
1401  }
1402  break;
1403  }
1404 
1405  case WID_O_DELETE:
1406  this->OrderClick_Delete();
1407  break;
1408 
1409  case WID_O_STOP_SHARING:
1410  this->OrderClick_StopSharing();
1411  break;
1412  }
1413 
1415 
1416  if (this->order_over != INVALID_VEH_ORDER_ID) {
1417  /* End of drag-and-drop, hide dragged order destination highlight. */
1420  }
1421  }
1422 
1423  virtual EventState OnHotkey(int hotkey)
1424  {
1425  if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1426 
1427  switch (hotkey) {
1428  case OHK_SKIP: this->OrderClick_Skip(); break;
1429  case OHK_DELETE: this->OrderClick_Delete(); break;
1430  case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1431  case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1432  case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1433  case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1434  case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1435  case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1436  case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1437  case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1438  case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1439  default: return ES_NOT_HANDLED;
1440  }
1441  return ES_HANDLED;
1442  }
1443 
1444  virtual void OnPlaceObject(Point pt, TileIndex tile)
1445  {
1446  if (this->goto_type == OPOS_GOTO) {
1447  const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1448  if (cmd.IsType(OT_NOTHING)) return;
1449 
1450  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))) {
1451  /* With quick goto the Go To button stays active */
1453  }
1454  }
1455  }
1456 
1457  virtual bool OnVehicleSelect(const Vehicle *v)
1458  {
1459  /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1460  * We disallow copying orders of other vehicles if we already have at least one order entry
1461  * ourself as it easily copies orders of vehicles within a station when we mean the station.
1462  * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1463  * TODO: give a warning message */
1464  bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1465  if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1466 
1467  if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1468  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))) {
1469  this->selected_order = -1;
1471  }
1472  return true;
1473  }
1474 
1475  virtual void OnPlaceObjectAbort()
1476  {
1477  this->goto_type = OPOS_NONE;
1478  this->SetWidgetDirty(WID_O_GOTO);
1479 
1480  /* Remove drag highlighting if it exists. */
1481  if (this->order_over != INVALID_VEH_ORDER_ID) {
1484  }
1485  }
1486 
1487  virtual void OnMouseDrag(Point pt, int widget)
1488  {
1489  if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1490  /* An order is dragged.. */
1491  VehicleOrderID from_order = this->OrderGetSel();
1492  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1493  uint num_orders = this->vehicle->GetNumOrders();
1494 
1495  if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1496  if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1497  this->order_over = to_order;
1498  this->SetWidgetDirty(widget);
1499  } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1501  this->SetWidgetDirty(widget);
1502  }
1503  }
1504  }
1505  }
1506 
1507  virtual void OnResize()
1508  {
1509  /* Update the scroll bar */
1510  this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1511  }
1512 
1513  static HotkeyList hotkeys;
1514 };
1515 
1516 static Hotkey order_hotkeys[] = {
1517  Hotkey('D', "skip", OHK_SKIP),
1518  Hotkey('F', "delete", OHK_DELETE),
1519  Hotkey('G', "goto", OHK_GOTO),
1520  Hotkey('H', "nonstop", OHK_NONSTOP),
1521  Hotkey('J', "fullload", OHK_FULLLOAD),
1522  Hotkey('K', "unload", OHK_UNLOAD),
1523  Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1524  Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1525  Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1526  Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1527  Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1528  HOTKEY_LIST_END
1529 };
1530 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1531 
1535  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1536  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1537  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1538  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1539  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1540  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1541  EndContainer(),
1543  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(),
1544  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1545  EndContainer(),
1546 
1547  /* First button row. */
1551  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1552  SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1553  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1554  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1555  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1556  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1557  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1558  EndContainer(),
1559  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1560  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1561  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1562  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1563  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1564  EndContainer(),
1565  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1566  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1567  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1569  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1570  EndContainer(),
1571  EndContainer(),
1573  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1574  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1575  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1576  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1577  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1578  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1579  EndContainer(),
1580  EndContainer(),
1581  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),
1582  EndContainer(),
1583 
1584  /* Second button row. */
1587  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1588  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1590  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1591  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1592  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1593  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1594  EndContainer(),
1595  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1596  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1597  EndContainer(),
1598  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1599  EndContainer(),
1600 };
1601 
1602 static WindowDesc _orders_train_desc(
1603  WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1606  _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1607  &OrdersWindow::hotkeys
1608 );
1609 
1613  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1614  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1615  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1616  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1617  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1618  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1619  EndContainer(),
1621  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(),
1622  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1623  EndContainer(),
1624 
1625  /* First button row. */
1627  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1628  /* Load + unload + refit buttons. */
1630  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1631  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1632  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1633  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1635  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1636  EndContainer(),
1637  /* Refit + service buttons. */
1639  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1640  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1641  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1642  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1643  EndContainer(),
1644 
1645  /* Buttons for setting a condition. */
1647  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1648  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1649  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1650  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1651  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1652  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1653  EndContainer(),
1654  EndContainer(),
1655 
1656  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),
1657  EndContainer(),
1658 
1659  /* Second button row. */
1661  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1662  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1664  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1665  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1666  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1667  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1668  EndContainer(),
1669  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1670  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1671  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1672  EndContainer(),
1673 };
1674 
1675 static WindowDesc _orders_desc(
1676  WDP_AUTO, "view_vehicle_orders", 384, 100,
1679  _nested_orders_widgets, lengthof(_nested_orders_widgets),
1680  &OrdersWindow::hotkeys
1681 );
1682 
1686  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1687  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1688  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1689  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1690  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1691  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1692  EndContainer(),
1694  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(),
1696  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1697  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1698  EndContainer(),
1699  EndContainer(),
1700 };
1701 
1702 static WindowDesc _other_orders_desc(
1703  WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1706  _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1707  &OrdersWindow::hotkeys
1708 );
1709 
1710 void ShowOrdersWindow(const Vehicle *v)
1711 {
1714  if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1715 
1716  /* Using a different WindowDescs for _local_company causes problems.
1717  * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
1718  * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1719  * in crashed due to missing widges.
1720  * TODO Rewrite the order GUI to not use different WindowDescs.
1721  */
1722  if (v->owner != _local_company) {
1723  new OrdersWindow(&_other_orders_desc, v);
1724  } else {
1725  new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
1726  }
1727 }