OpenTTD
order_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
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 
157  OCV_AGE,
161 };
162 
163 static const StringID _order_conditional_condition[] = {
164  STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
165  STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
166  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
167  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
168  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
169  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
170  STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
171  STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
173 };
174 
175 extern uint ConvertSpeedToDisplaySpeed(uint speed);
176 extern uint ConvertDisplaySpeedToSpeed(uint speed);
177 
178 static const StringID _order_depot_action_dropdown[] = {
179  STR_ORDER_DROP_GO_ALWAYS_DEPOT,
180  STR_ORDER_DROP_SERVICE_DEPOT,
181  STR_ORDER_DROP_HALT_DEPOT,
183 };
184 
185 static int DepotActionStringIndex(const Order *order)
186 {
187  if (order->GetDepotActionType() & ODATFB_HALT) {
188  return DA_STOP;
189  } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
190  return DA_SERVICE;
191  } else {
192  return DA_ALWAYS_GO;
193  }
194 }
195 
196 static const StringID _order_refit_action_dropdown[] = {
197  STR_ORDER_DROP_REFIT_AUTO,
198  STR_ORDER_DROP_REFIT_AUTO_ANY,
200 };
201 
214 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
215 {
216  bool rtl = _current_text_dir == TD_RTL;
217 
218  SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
219  Dimension sprite_size = GetSpriteSize(sprite);
220  if (v->cur_real_order_index == order_index) {
221  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
222  DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
223  } else if (v->cur_implicit_order_index == order_index) {
224  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
225  }
226 
227  TextColour colour = TC_BLACK;
228  if (order->IsType(OT_IMPLICIT)) {
229  colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
230  } else if (selected) {
231  colour = TC_WHITE;
232  }
233 
234  SetDParam(0, order_index + 1);
235  DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
236 
237  SetDParam(5, STR_EMPTY);
238  SetDParam(8, STR_EMPTY);
239 
240  /* Check range for aircraft. */
241  if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
242  const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
243  if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
244  }
245 
246  switch (order->GetType()) {
247  case OT_DUMMY:
248  SetDParam(0, STR_INVALID_ORDER);
249  SetDParam(1, order->GetDestination());
250  break;
251 
252  case OT_IMPLICIT:
253  SetDParam(0, STR_ORDER_GO_TO_STATION);
254  SetDParam(1, STR_ORDER_GO_TO);
255  SetDParam(2, order->GetDestination());
256  SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
257  break;
258 
259  case OT_GOTO_STATION: {
260  OrderLoadFlags load = order->GetLoadType();
261  OrderUnloadFlags unload = order->GetUnloadType();
262 
263  SetDParam(0, STR_ORDER_GO_TO_STATION);
264  SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
265  SetDParam(2, order->GetDestination());
266 
267  if (timetable) {
268  SetDParam(3, STR_EMPTY);
269 
270  if (order->GetWaitTime() > 0) {
271  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
272  SetTimetableParams(6, 7, order->GetWaitTime());
273  }
274  } else {
275  SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
276  if (order->IsRefit()) {
277  SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
278  }
279  if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
280  SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
281  }
282  }
283  break;
284  }
285 
286  case OT_GOTO_DEPOT:
287  if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
288  SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
289  if (v->type == VEH_AIRCRAFT) {
290  SetDParam(2, STR_ORDER_NEAREST_HANGAR);
291  SetDParam(3, STR_EMPTY);
292  } else {
293  SetDParam(2, STR_ORDER_NEAREST_DEPOT);
294  SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
295  }
296  } else {
297  SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
298  SetDParam(2, v->type);
299  SetDParam(3, order->GetDestination());
300  }
301 
302  if (order->GetDepotOrderType() & ODTFB_SERVICE) {
303  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
304  } else {
305  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
306  }
307 
308  if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
309  SetDParam(5, STR_ORDER_STOP_ORDER);
310  }
311 
312  if (!timetable && order->IsRefit()) {
313  SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
314  SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
315  }
316  break;
317 
318  case OT_GOTO_WAYPOINT:
319  SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
320  SetDParam(1, order->GetDestination());
321  break;
322 
323  case OT_CONDITIONAL:
324  SetDParam(1, order->GetConditionSkipToOrder() + 1);
325  if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
326  SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
327  } else {
329  SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
330  SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
331  SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
332 
333  uint value = order->GetConditionValue();
334  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
335  SetDParam(4, value);
336  }
337 
338  if (timetable && order->GetWaitTime() > 0) {
339  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
340  SetTimetableParams(6, 7, order->GetWaitTime());
341  } else {
342  SetDParam(5, STR_EMPTY);
343  }
344  break;
345 
346  default: NOT_REACHED();
347  }
348 
349  DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
350 }
351 
359 {
360  /* Hack-ish; unpack order 0, so everything gets initialised with either zero
361  * or a suitable default value for the variable. Then also override the index
362  * as it is not coming from a pool, so would be initialised. */
363  Order order(0);
364  order.index = 0;
365 
366  /* check depot first */
367  if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
368  order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
371 
373 
374  return order;
375  }
376 
377  /* check rail waypoint */
378  if (IsRailWaypointTile(tile) &&
379  v->type == VEH_TRAIN &&
380  IsTileOwner(tile, _local_company)) {
381  order.MakeGoToWaypoint(GetStationIndex(tile));
383  return order;
384  }
385 
386  /* check buoy (no ownership) */
387  if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
388  order.MakeGoToWaypoint(GetStationIndex(tile));
389  return order;
390  }
391 
392  if (IsTileType(tile, MP_STATION)) {
393  StationID st_index = GetStationIndex(tile);
394  const Station *st = Station::Get(st_index);
395 
396  if (st->owner == _local_company || st->owner == OWNER_NONE) {
397  byte facil;
398  (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
399  (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
400  (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
401  (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
402  (facil = FACIL_TRUCK_STOP, 1);
403  if (st->facilities & facil) {
404  order.MakeGoToStation(st_index);
408  return order;
409  }
410  }
411  }
412 
413  /* not found */
414  order.Free();
415  return order;
416 }
417 
419 enum {
420  OHK_SKIP,
421  OHK_DELETE,
422  OHK_GOTO,
423  OHK_NONSTOP,
424  OHK_FULLLOAD,
425  OHK_UNLOAD,
426  OHK_NEAREST_DEPOT,
427  OHK_ALWAYS_SERVICE,
428  OHK_TRANSFER,
429  OHK_NO_UNLOAD,
430  OHK_NO_LOAD,
431 };
432 
473 struct OrdersWindow : public Window {
474 private:
477  OPOS_NONE,
478  OPOS_GOTO,
479  OPOS_CONDITIONAL,
480  OPOS_SHARE,
481  OPOS_END,
482  };
483 
485  enum DisplayPane {
486  /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
489 
490  /* WID_O_SEL_TOP_LEFT */
493 
494  /* WID_O_SEL_TOP_MIDDLE */
497 
498  /* WID_O_SEL_TOP_RIGHT */
501 
502  /* WID_O_SEL_TOP_ROW */
506 
507  /* WID_O_SEL_BOTTOM_MIDDLE */
510  };
511 
512  int selected_order;
514  OrderPlaceObjectState goto_type;
515  const Vehicle *vehicle;
516  Scrollbar *vscroll;
519 
526  {
527  int num = this->selected_order;
528  return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
529  }
530 
540  {
541  NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
542  int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
543 
544  if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
545 
546  sel += this->vscroll->GetPosition();
547 
548  return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
549  }
550 
555  {
556  assert(type > OPOS_NONE && type < OPOS_END);
557 
558  static const HighLightStyle goto_place_style[OPOS_END - 1] = {
559  HT_RECT | HT_VEHICLE, // OPOS_GOTO
560  HT_NONE, // OPOS_CONDITIONAL
561  HT_VEHICLE, // OPOS_SHARE
562  };
563  SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
564  this->goto_type = type;
565  this->SetWidgetDirty(WID_O_GOTO);
566  }
567 
572  void OrderClick_FullLoad(int load_type)
573  {
574  VehicleOrderID sel_ord = this->OrderGetSel();
575  const Order *order = this->vehicle->GetOrder(sel_ord);
576 
577  if (order == NULL || order->GetLoadType() == load_type) return;
578 
579  if (load_type < 0) {
581  }
582  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));
583  }
584 
589  {
591  }
592 
596  void OrderClick_Service(int i)
597  {
598  VehicleOrderID sel_ord = this->OrderGetSel();
599 
600  if (i < 0) {
601  const Order *order = this->vehicle->GetOrder(sel_ord);
602  if (order == NULL) return;
604  }
605  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));
606  }
607 
612  {
613  Order order;
614  order.next = NULL;
615  order.index = 0;
619 
620  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
621  }
622 
626  void OrderClick_Unload(int unload_type)
627  {
628  VehicleOrderID sel_ord = this->OrderGetSel();
629  const Order *order = this->vehicle->GetOrder(sel_ord);
630 
631  if (order == NULL || order->GetUnloadType() == unload_type) return;
632 
633  if (unload_type < 0) {
635  }
636 
637  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));
638 
639  /* Transfer orders with leave empty as default */
640  if (unload_type == OUFB_TRANSFER) {
641  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
643  }
644  }
645 
650  {
652  }
653 
658  {
660  }
661 
666  void OrderClick_Nonstop(int non_stop)
667  {
668  if (!this->vehicle->IsGroundVehicle()) return;
669 
670  VehicleOrderID sel_ord = this->OrderGetSel();
671  const Order *order = this->vehicle->GetOrder(sel_ord);
672 
673  if (order == NULL || order->GetNonStopType() == non_stop) return;
674 
675  /* Keypress if negative, so 'toggle' to the next */
676  if (non_stop < 0) {
678  }
679 
681  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));
682  }
683 
689  {
690  /* Don't skip when there's nothing to skip */
691  if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
692  if (this->vehicle->GetNumOrders() <= 1) return;
693 
694  DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
695  CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
696  }
697 
702  {
703  /* When networking, move one order lower */
704  int selected = this->selected_order + (int)_networking;
705 
706  if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
707  this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
708  this->UpdateButtonState();
709  }
710  }
711 
719  {
720  /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
721  if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
722  /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
723  if (_ctrl_pressed) {
724  this->OrderClick_Delete();
725  return;
726  }
727 
728  /* Get another vehicle that share orders with this vehicle. */
729  Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
730  /* Copy the order list of the other vehicle. */
731  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))) {
732  this->UpdateButtonState();
733  }
734  }
735 
742  void OrderClick_Refit(int i, bool auto_refit)
743  {
744  if (_ctrl_pressed) {
745  /* Cancel refitting */
746  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
747  } else {
748  if (i == 1) { // Auto-refit to available cargo type.
749  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
750  } else {
751  ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
752  }
753  }
754  }
755 
758  {
759  this->can_do_refit = false;
760  this->can_do_autorefit = false;
761  for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
762  if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
763  if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
764  }
765  }
766 
767 public:
768  OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
769  {
770  this->vehicle = v;
771 
772  this->CreateNestedTree();
773  this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
774  this->FinishInitNested(v->index);
775  if (v->owner == _local_company) {
776  this->DisableWidget(WID_O_EMPTY);
777  }
778 
779  this->selected_order = -1;
780  this->order_over = INVALID_VEH_ORDER_ID;
781  this->goto_type = OPOS_NONE;
782  this->owner = v->owner;
783 
784  this->UpdateAutoRefitState();
785 
787  /* If there are less than 2 station, make Go To active. */
788  int station_orders = 0;
789  const Order *order;
790  FOR_VEHICLE_ORDERS(v, order) {
791  if (order->IsType(OT_GOTO_STATION)) station_orders++;
792  }
793 
794  if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
795  }
797  }
798 
799  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
800  {
801  switch (widget) {
802  case WID_O_ORDER_LIST:
803  resize->height = FONT_HEIGHT_NORMAL;
804  size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
805  break;
806 
807  case WID_O_COND_VARIABLE: {
808  Dimension d = {0, 0};
809  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
810  d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
811  }
812  d.width += padding.width;
813  d.height += padding.height;
814  *size = maxdim(*size, d);
815  break;
816  }
817 
818  case WID_O_COND_COMPARATOR: {
819  Dimension d = {0, 0};
820  for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
821  d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
822  }
823  d.width += padding.width;
824  d.height += padding.height;
825  *size = maxdim(*size, d);
826  break;
827  }
828  }
829  }
830 
836  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
837  {
840 
841  switch (data) {
842  case VIWD_AUTOREPLACE:
843  /* Autoreplace replaced the vehicle */
844  this->vehicle = Vehicle::Get(this->window_number);
845  FALLTHROUGH;
846 
848  /* Vehicle composition was changed. */
849  this->UpdateAutoRefitState();
850  break;
851 
853  /* Removed / replaced all orders (after deleting / sharing) */
854  if (this->selected_order == -1) break;
855 
856  this->DeleteChildWindows();
857  HideDropDownMenu(this);
858  this->selected_order = -1;
859  break;
860 
861  case VIWD_MODIFY_ORDERS:
862  /* Some other order changes */
863  break;
864 
865  default:
866  if (data < 0) break;
867 
868  if (gui_scope) break; // only do this once; from command scope
869  from = GB(data, 0, 8);
870  to = GB(data, 8, 8);
871  /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
872  * the order is being created / removed */
873  if (this->selected_order == -1) break;
874 
875  if (from == to) break; // no need to change anything
876 
877  if (from != this->selected_order) {
878  /* Moving from preceding order? */
879  this->selected_order -= (int)(from <= this->selected_order);
880  /* Moving to preceding order? */
881  this->selected_order += (int)(to <= this->selected_order);
882  break;
883  }
884 
885  /* Now we are modifying the selected order */
886  if (to == INVALID_VEH_ORDER_ID) {
887  /* Deleting selected order */
888  this->DeleteChildWindows();
889  HideDropDownMenu(this);
890  this->selected_order = -1;
891  break;
892  }
893 
894  /* Moving selected order */
895  this->selected_order = to;
896  break;
897  }
898 
899  this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
900  if (gui_scope) this->UpdateButtonState();
901 
902  /* Scroll to the new order. */
903  if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
904  this->vscroll->ScrollTowards(to);
905  }
906  }
907 
908  void UpdateButtonState()
909  {
910  if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
911 
912  bool shared_orders = this->vehicle->IsOrderListShared();
913  VehicleOrderID sel = this->OrderGetSel();
914  const Order *order = this->vehicle->GetOrder(sel);
915 
916  /* Second row. */
917  /* skip */
918  this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
919 
920  /* delete / stop sharing */
921  NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
922  if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
923  /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
925  } else {
926  /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
927  delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
929  (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
930 
931  /* Set the tooltip of the 'delete' button depending on whether the
932  * 'End of Orders' order or a regular order is selected. */
933  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
934  if (this->selected_order == this->vehicle->GetNumOrders()) {
935  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
936  } else {
937  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
938  }
939  }
940 
941  /* First row. */
943  this->RaiseWidget(WID_O_UNLOAD);
944  this->RaiseWidget(WID_O_SERVICE);
945 
946  /* Selection widgets. */
947  /* Train or road vehicle. */
948  NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
949  NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
950  NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
951  NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
952  /* Ship or airplane. */
953  NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
954  assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
955 
956 
957  if (order == NULL) {
958  if (row_sel != NULL) {
959  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
960  } else {
962  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
963  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
964  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
967  }
971  } else {
974 
975  switch (order->GetType()) {
976  case OT_GOTO_STATION:
977  if (row_sel != NULL) {
978  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
979  } else {
981  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
982  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
983  right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
986  }
989 
990  /* Can only do refitting when stopping at the destination and loading cargo.
991  * Also enable the button if a refit is already set to allow clearing it. */
994  ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
995 
996  break;
997 
998  case OT_GOTO_WAYPOINT:
999  if (row_sel != NULL) {
1000  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1001  } else {
1003  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1004  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1005  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1008  }
1010  this->DisableWidget(WID_O_UNLOAD);
1012  break;
1013 
1014  case OT_GOTO_DEPOT:
1015  if (row_sel != NULL) {
1016  row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1017  } else {
1019  left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1020  middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1021  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1024  }
1025  /* Disable refit button if the order is no 'always go' order.
1026  * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1028  (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1029  (!this->can_do_refit && !order->IsRefit()));
1031  break;
1032 
1033  case OT_CONDITIONAL: {
1034  if (row_sel != NULL) {
1035  row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1036  } else {
1038  }
1040  /* Set the strings for the dropdown boxes. */
1041  this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1042  this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1045  break;
1046  }
1047 
1048  default: // every other order
1049  if (row_sel != NULL) {
1050  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1051  } else {
1053  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1054  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1055  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1057  }
1059  this->DisableWidget(WID_O_UNLOAD);
1061  break;
1062  }
1063  }
1064 
1065  /* Disable list of vehicles with the same shared orders if there is no list */
1066  this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1067 
1068  this->SetDirty();
1069  }
1070 
1071  virtual void OnPaint()
1072  {
1073  if (this->vehicle->owner != _local_company) {
1074  this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1075  } else {
1076  this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1077  }
1078  this->DrawWidgets();
1079  }
1080 
1081  virtual void DrawWidget(const Rect &r, int widget) const
1082  {
1083  if (widget != WID_O_ORDER_LIST) return;
1084 
1085  bool rtl = _current_text_dir == TD_RTL;
1086  SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1087  int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1088  int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1089 
1090  int y = r.top + WD_FRAMERECT_TOP;
1091  int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1092 
1093  int i = this->vscroll->GetPosition();
1094  const Order *order = this->vehicle->GetOrder(i);
1095  /* First draw the highlighting underground if it exists. */
1096  if (this->order_over != INVALID_VEH_ORDER_ID) {
1097  while (order != NULL) {
1098  /* Don't draw anything if it extends past the end of the window. */
1099  if (!this->vscroll->IsVisible(i)) break;
1100 
1101  if (i != this->selected_order && i == this->order_over) {
1102  /* Highlight dragged order destination. */
1103  int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1104  int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1105  top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1106  GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1107  break;
1108  }
1109  y += line_height;
1110 
1111  i++;
1112  order = order->next;
1113  }
1114 
1115  /* Reset counters for drawing the orders. */
1116  y = r.top + WD_FRAMERECT_TOP;
1117  i = this->vscroll->GetPosition();
1118  order = this->vehicle->GetOrder(i);
1119  }
1120 
1121  /* Draw the orders. */
1122  while (order != NULL) {
1123  /* Don't draw anything if it extends past the end of the window. */
1124  if (!this->vscroll->IsVisible(i)) break;
1125 
1126  DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1127  y += line_height;
1128 
1129  i++;
1130  order = order->next;
1131  }
1132 
1133  if (this->vscroll->IsVisible(i)) {
1134  StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1135  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);
1136  }
1137  }
1138 
1139  virtual void SetStringParameters(int widget) const
1140  {
1141  switch (widget) {
1142  case WID_O_COND_VALUE: {
1143  VehicleOrderID sel = this->OrderGetSel();
1144  const Order *order = this->vehicle->GetOrder(sel);
1145 
1146  if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1147  uint value = order->GetConditionValue();
1148  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1149  SetDParam(0, value);
1150  }
1151  break;
1152  }
1153 
1154  case WID_O_CAPTION:
1155  SetDParam(0, this->vehicle->index);
1156  break;
1157  }
1158  }
1159 
1160  virtual void OnClick(Point pt, int widget, int click_count)
1161  {
1162  switch (widget) {
1163  case WID_O_ORDER_LIST: {
1164  if (this->goto_type == OPOS_CONDITIONAL) {
1165  VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1166  if (order_id != INVALID_VEH_ORDER_ID) {
1167  Order order;
1168  order.next = NULL;
1169  order.index = 0;
1170  order.MakeConditional(order_id);
1171 
1172  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1173  }
1175  break;
1176  }
1177 
1178  VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1179 
1180  if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1181  TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1182  if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1183  return;
1184  }
1185 
1186  /* This order won't be selected any more, close all child windows and dropdowns */
1187  this->DeleteChildWindows();
1188  HideDropDownMenu(this);
1189 
1190  if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1191  /* Deselect clicked order */
1192  this->selected_order = -1;
1193  } else if (sel == this->selected_order) {
1194  if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1195  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1196  MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1197  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1198  }
1199  } else {
1200  /* Select clicked order */
1201  this->selected_order = sel;
1202 
1203  if (this->vehicle->owner == _local_company) {
1204  /* Activate drag and drop */
1205  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1206  }
1207  }
1208 
1209  this->UpdateButtonState();
1210  break;
1211  }
1212 
1213  case WID_O_SKIP:
1214  this->OrderClick_Skip();
1215  break;
1216 
1217  case WID_O_DELETE:
1218  this->OrderClick_Delete();
1219  break;
1220 
1221  case WID_O_STOP_SHARING:
1222  this->OrderClick_StopSharing();
1223  break;
1224 
1225  case WID_O_NON_STOP:
1226  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1227  this->OrderClick_Nonstop(-1);
1228  } else {
1229  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1230  ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1231  o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1232  }
1233  break;
1234 
1235  case WID_O_GOTO:
1236  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1237  if (this->goto_type != OPOS_NONE) {
1239  } else {
1240  this->OrderClick_Goto(OPOS_GOTO);
1241  }
1242  } else {
1243  int sel;
1244  switch (this->goto_type) {
1245  case OPOS_NONE: sel = -1; break;
1246  case OPOS_GOTO: sel = 0; break;
1247  case OPOS_CONDITIONAL: sel = 2; break;
1248  case OPOS_SHARE: sel = 3; break;
1249  default: NOT_REACHED();
1250  }
1251  ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1252  }
1253  break;
1254 
1255  case WID_O_FULL_LOAD:
1256  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1257  this->OrderClick_FullLoad(-1);
1258  } else {
1259  ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1260  }
1261  break;
1262 
1263  case WID_O_UNLOAD:
1264  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1265  this->OrderClick_Unload(-1);
1266  } else {
1267  ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1268  }
1269  break;
1270 
1271  case WID_O_REFIT:
1272  this->OrderClick_Refit(0, false);
1273  break;
1274 
1275  case WID_O_SERVICE:
1276  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1277  this->OrderClick_Service(-1);
1278  } else {
1279  ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1280  }
1281  break;
1282 
1283  case WID_O_REFIT_DROPDOWN:
1284  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1285  this->OrderClick_Refit(0, true);
1286  } else {
1287  ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1288  }
1289  break;
1290 
1291  case WID_O_TIMETABLE_VIEW:
1292  ShowTimetableWindow(this->vehicle);
1293  break;
1294 
1295  case WID_O_COND_VARIABLE: {
1296  DropDownList *list = new DropDownList();
1297  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1298  *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1299  }
1300  ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1301  break;
1302  }
1303 
1304  case WID_O_COND_COMPARATOR: {
1305  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1306  ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1307  break;
1308  }
1309 
1310  case WID_O_COND_VALUE: {
1311  const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1312  uint value = order->GetConditionValue();
1313  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1314  SetDParam(0, value);
1315  ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1316  break;
1317  }
1318 
1320  ShowVehicleListWindow(this->vehicle);
1321  break;
1322  }
1323  }
1324 
1325  virtual void OnQueryTextFinished(char *str)
1326  {
1327  if (!StrEmpty(str)) {
1328  VehicleOrderID sel = this->OrderGetSel();
1329  uint value = atoi(str);
1330 
1331  switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1332  case OCV_MAX_SPEED:
1333  value = ConvertDisplaySpeedToSpeed(value);
1334  break;
1335 
1336  case OCV_RELIABILITY:
1337  case OCV_LOAD_PERCENTAGE:
1338  value = Clamp(value, 0, 100);
1339  break;
1340 
1341  default:
1342  break;
1343  }
1344  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));
1345  }
1346  }
1347 
1348  virtual void OnDropdownSelect(int widget, int index)
1349  {
1350  switch (widget) {
1351  case WID_O_NON_STOP:
1352  this->OrderClick_Nonstop(index);
1353  break;
1354 
1355  case WID_O_FULL_LOAD:
1356  this->OrderClick_FullLoad(index);
1357  break;
1358 
1359  case WID_O_UNLOAD:
1360  this->OrderClick_Unload(index);
1361  break;
1362 
1363  case WID_O_GOTO:
1364  switch (index) {
1365  case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1366  case 1: this->OrderClick_NearestDepot(); break;
1367  case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1368  case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1369  default: NOT_REACHED();
1370  }
1371  break;
1372 
1373  case WID_O_SERVICE:
1374  this->OrderClick_Service(index);
1375  break;
1376 
1377  case WID_O_REFIT_DROPDOWN:
1378  this->OrderClick_Refit(index, true);
1379  break;
1380 
1381  case WID_O_COND_VARIABLE:
1382  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));
1383  break;
1384 
1385  case WID_O_COND_COMPARATOR:
1386  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));
1387  break;
1388  }
1389  }
1390 
1391  virtual void OnDragDrop(Point pt, int widget)
1392  {
1393  switch (widget) {
1394  case WID_O_ORDER_LIST: {
1395  VehicleOrderID from_order = this->OrderGetSel();
1396  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1397 
1398  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()) &&
1399  DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1400  this->selected_order = -1;
1401  this->UpdateButtonState();
1402  }
1403  break;
1404  }
1405 
1406  case WID_O_DELETE:
1407  this->OrderClick_Delete();
1408  break;
1409 
1410  case WID_O_STOP_SHARING:
1411  this->OrderClick_StopSharing();
1412  break;
1413  }
1414 
1416 
1417  if (this->order_over != INVALID_VEH_ORDER_ID) {
1418  /* End of drag-and-drop, hide dragged order destination highlight. */
1419  this->order_over = INVALID_VEH_ORDER_ID;
1421  }
1422  }
1423 
1424  virtual EventState OnHotkey(int hotkey)
1425  {
1426  if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1427 
1428  switch (hotkey) {
1429  case OHK_SKIP: this->OrderClick_Skip(); break;
1430  case OHK_DELETE: this->OrderClick_Delete(); break;
1431  case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1432  case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1433  case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1434  case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1435  case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1436  case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1437  case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1438  case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1439  case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1440  default: return ES_NOT_HANDLED;
1441  }
1442  return ES_HANDLED;
1443  }
1444 
1445  virtual void OnPlaceObject(Point pt, TileIndex tile)
1446  {
1447  if (this->goto_type == OPOS_GOTO) {
1448  const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1449  if (cmd.IsType(OT_NOTHING)) return;
1450 
1451  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))) {
1452  /* With quick goto the Go To button stays active */
1454  }
1455  }
1456  }
1457 
1458  virtual bool OnVehicleSelect(const Vehicle *v)
1459  {
1460  /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1461  * We disallow copying orders of other vehicles if we already have at least one order entry
1462  * ourself as it easily copies orders of vehicles within a station when we mean the station.
1463  * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1464  * TODO: give a warning message */
1465  bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1466  if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1467 
1468  if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1469  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))) {
1470  this->selected_order = -1;
1472  }
1473  return true;
1474  }
1475 
1476  virtual void OnPlaceObjectAbort()
1477  {
1478  this->goto_type = OPOS_NONE;
1479  this->SetWidgetDirty(WID_O_GOTO);
1480 
1481  /* Remove drag highlighting if it exists. */
1482  if (this->order_over != INVALID_VEH_ORDER_ID) {
1483  this->order_over = INVALID_VEH_ORDER_ID;
1485  }
1486  }
1487 
1488  virtual void OnMouseDrag(Point pt, int widget)
1489  {
1490  if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1491  /* An order is dragged.. */
1492  VehicleOrderID from_order = this->OrderGetSel();
1493  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1494  uint num_orders = this->vehicle->GetNumOrders();
1495 
1496  if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1497  if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1498  this->order_over = to_order;
1499  this->SetWidgetDirty(widget);
1500  } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1501  this->order_over = INVALID_VEH_ORDER_ID;
1502  this->SetWidgetDirty(widget);
1503  }
1504  }
1505  }
1506  }
1507 
1508  virtual void OnResize()
1509  {
1510  /* Update the scroll bar */
1511  this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1512  }
1513 
1514  static HotkeyList hotkeys;
1515 };
1516 
1517 static Hotkey order_hotkeys[] = {
1518  Hotkey('D', "skip", OHK_SKIP),
1519  Hotkey('F', "delete", OHK_DELETE),
1520  Hotkey('G', "goto", OHK_GOTO),
1521  Hotkey('H', "nonstop", OHK_NONSTOP),
1522  Hotkey('J', "fullload", OHK_FULLLOAD),
1523  Hotkey('K', "unload", OHK_UNLOAD),
1524  Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1525  Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1526  Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1527  Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1528  Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1529  HOTKEY_LIST_END
1530 };
1531 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1532 
1536  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1537  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1538  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1539  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1540  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1541  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1542  EndContainer(),
1544  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(),
1545  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1546  EndContainer(),
1547 
1548  /* First button row. */
1552  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1553  SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1554  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1555  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1556  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1557  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1558  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1559  EndContainer(),
1560  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1561  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1562  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1563  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1564  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1565  EndContainer(),
1566  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1567  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1568  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1570  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1571  EndContainer(),
1572  EndContainer(),
1574  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1575  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1576  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1577  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1578  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1579  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1580  EndContainer(),
1581  EndContainer(),
1582  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),
1583  EndContainer(),
1584 
1585  /* Second button row. */
1588  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1589  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1591  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1592  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1593  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1594  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1595  EndContainer(),
1596  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1597  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1598  EndContainer(),
1599  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1600  EndContainer(),
1601 };
1602 
1603 static WindowDesc _orders_train_desc(
1604  WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1607  _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1608  &OrdersWindow::hotkeys
1609 );
1610 
1614  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1615  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1616  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1617  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1618  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1619  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1620  EndContainer(),
1622  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(),
1623  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1624  EndContainer(),
1625 
1626  /* First button row. */
1628  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1629  /* Load + unload + refit buttons. */
1631  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1632  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1633  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1634  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1636  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1637  EndContainer(),
1638  /* Refit + service buttons. */
1640  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1641  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1642  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1643  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1644  EndContainer(),
1645 
1646  /* Buttons for setting a condition. */
1648  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1649  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1650  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1651  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1652  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1653  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1654  EndContainer(),
1655  EndContainer(),
1656 
1657  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),
1658  EndContainer(),
1659 
1660  /* Second button row. */
1662  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1663  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1665  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1666  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1667  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1668  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1669  EndContainer(),
1670  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1671  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1672  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1673  EndContainer(),
1674 };
1675 
1676 static WindowDesc _orders_desc(
1677  WDP_AUTO, "view_vehicle_orders", 384, 100,
1680  _nested_orders_widgets, lengthof(_nested_orders_widgets),
1681  &OrdersWindow::hotkeys
1682 );
1683 
1687  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1688  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1689  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1690  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1691  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1692  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1693  EndContainer(),
1695  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(),
1697  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1698  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1699  EndContainer(),
1700  EndContainer(),
1701 };
1702 
1703 static WindowDesc _other_orders_desc(
1704  WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1707  _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1708  &OrdersWindow::hotkeys
1709 );
1710 
1711 void ShowOrdersWindow(const Vehicle *v)
1712 {
1715  if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1716 
1717  /* Using a different WindowDescs for _local_company causes problems.
1718  * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
1719  * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1720  * in crashed due to missing widges.
1721  * TODO Rewrite the order GUI to not use different WindowDescs.
1722  */
1723  if (v->owner != _local_company) {
1724  new OrdersWindow(&_other_orders_desc, v);
1725  } else {
1726  new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
1727  }
1728 }
OrderConditionVariable
Variables (of a vehicle) to &#39;cause&#39; skipping on.
Definition: order_type.h:118
EventState
State of handling an event.
Definition: window_type.h:713
void OrderClick_NearestDepot()
Handle the click on the service in nearest depot button.
Definition: order_gui.cpp:611
NWID_SELECTION widget for the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:38
Functions related to OTTD&#39;s strings.
Display the row for normal/depot orders in the top row of the train/rv order window.
Definition: order_gui.cpp:487
Road vehicle states.
static const StringID _station_load_types[][5][5]
Order load types that could be given to station orders.
Definition: order_gui.cpp:39
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
uint ConvertSpeedToDisplaySpeed(uint speed)
Convert the given (internal) speed to the display speed.
Definition: strings.cpp:724
bool _networking
are we in networking mode?
Definition: network.cpp:56
Passes an OrderUnloadType.
Definition: order_type.h:152
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
void OrderClick_StopSharing()
Handle the click on the &#39;stop sharing&#39; button.
Definition: order_gui.cpp:718
bool quick_goto
Allow quick access to &#39;goto button&#39; in vehicle orders window.
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:731
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Goto non-stop to destination.
Definition: order_widget.h:24
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1848
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:112
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:387
Point pos
logical mouse position
Definition: gfx_type.h:119
Stop sharing orders.
Definition: order_widget.h:23
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:448
Load as long as there is cargo that fits in the train.
Definition: order_type.h:69
void OrderClick_Skip()
Handle the click on the skip button.
Definition: order_gui.cpp:688
Delete selected order.
Definition: order_widget.h:22
bool IsGotoOrder() const
Is this a &#39;goto&#39; order with a real destination?
Definition: order_base.h:86
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition: order_base.h:143
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: order_gui.cpp:836
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
Open list of shared vehicles.
Definition: order_widget.h:41
Functions related to time tabling.
static const NWidgetPart _nested_other_orders_widgets[]
Nested widget definition for competitor orders.
Definition: order_gui.cpp:1685
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Hotkey related functions.
static const NWidgetPart _nested_orders_widgets[]
Nested widget definition for "your" orders (non-train).
Definition: order_gui.cpp:1612
void OrderClick_Refit(int i, bool auto_refit)
Handle the click on the refit button.
Definition: order_gui.cpp:742
Scrollbar data structure.
Definition: widget_type.h:589
Vehicle composition was changed.
Definition: vehicle_gui.h:36
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:405
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition: order_base.h:145
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:580
virtual void OnDragDrop(Point pt, int widget)
A dragged &#39;object&#39; has been released.
Definition: order_gui.cpp:1391
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:23
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Other order modifications.
Definition: vehicle_gui.h:35
Horizontal container.
Definition: widget_type.h:75
The passed event is not handled.
Definition: window_type.h:715
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
Definition: order_base.h:158
void OrderClick_Unload(int unload_type)
Handle the click on the unload button.
Definition: order_gui.cpp:626
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1064
NWID_SELECTION widget for right part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:37
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition: order_base.h:160
uint8 stop_location
what is the default stop location of trains?
Definition: settings_type.h:92
Select service (at depot).
Definition: order_widget.h:29
const Vehicle * vehicle
Vehicle owning the orders being displayed and manipulated.
Definition: order_gui.cpp:515
Placeholder for refit dropdown when not owner.
Definition: order_widget.h:30
Selects the OrderDepotAction.
Definition: order_type.h:154
Skip if the variable is true.
Definition: order_type.h:140
Skip based on the reliability.
Definition: order_type.h:120
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
A comparator changes.
Definition: order_type.h:156
Vehicle data structure.
Definition: vehicle_base.h:212
int top
y position of top edge of the window
Definition: window_gui.h:313
Unload all cargo that the station accepts.
Definition: order_type.h:59
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Close box (at top-left of a window)
Definition: widget_type.h:69
bool can_do_autorefit
Vehicle chain can be auto-refitted.
Definition: order_gui.cpp:518
Display &#39;refit&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:492
Base for aircraft.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:124
void OrderClick_Nonstop(int non_stop)
Handle the click on the nonstop button.
Definition: order_gui.cpp:666
clone (and share) an order
Definition: command_type.h:271
Stuff related to the text buffer GUI.
void UpdateAutoRefitState()
Cache auto-refittability of the vehicle chain.
Definition: order_gui.cpp:757
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:397
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:68
void OrderClick_Goto(OrderPlaceObjectState type)
Handle the click on the goto button.
Definition: order_gui.cpp:554
Display &#39;refit&#39; / &#39;service&#39; buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:504
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Skip based on the age.
Definition: order_type.h:122
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:478
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
Definition: order_cmd.cpp:671
Common string list item.
Definition: dropdown_type.h:41
NWID_SELECTION widget for the middle part of the bottom row of the &#39;your train&#39; order window...
Definition: order_widget.h:40
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1809
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:69
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:139
skip an order to the next of specific one
Definition: command_type.h:227
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:81
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: order_gui.cpp:1445
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Definition: order_cmd.cpp:698
T * Append(uint to_add=1)
Append an item and return it.
Order * next
Pointer to next order. If NULL, end of list.
Definition: order_base.h:51
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:675
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
bool IsAutoRefit() const
Is this order a auto-refit order.
Definition: order_base.h:117
Functions related to (drawing on) viewports.
Select refit.
Definition: order_widget.h:28
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: order_gui.cpp:1348
Display &#39;load&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:491
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1102
Data structure for an opened window.
Definition: window_gui.h:271
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
Stop at the far end of the platform.
Definition: order_type.h:92
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1825
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:79
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:37
virtual void OnResize()
Called after the window got resized.
Definition: order_gui.cpp:1508
Types related to the order widgets.
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
Definition: order_cmd.cpp:145
dragging items in the depot windows
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:216
Passes an OrderStopLocation.
Definition: order_type.h:151
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition: order_base.h:137
Vehicle orders; Window numbers:
Definition: window_type.h:207
Aircraft vehicle type.
Definition: vehicle_type.h:29
DisplayPane
Displayed planes of the NWID_SELECTION widgets.
Definition: order_gui.cpp:485
Map related accessors for depots.
Functions related to low-level strings.
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition: order_base.h:141
Display the row for conditional orders in the top row of the train/rv order window.
Definition: order_gui.cpp:488
Caption of the window.
Definition: order_widget.h:17
Only numeric ones.
Definition: string_type.h:28
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:154
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
Definition: order_gui.cpp:214
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
void OrderClick_Service(int i)
Handle the click on the service.
Definition: order_gui.cpp:596
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:894
bool IsRefit() const
Is this order a refit order.
Definition: order_base.h:110
The vehicle will not stop at any stations it passes including the destination.
Definition: order_type.h:82
Functions related to engines.
bool can_do_refit
Vehicle chain can be refitted in depot.
Definition: order_gui.cpp:517
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition: depot_map.h:20
Do not load anything.
Definition: order_type.h:72
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Simple vector template class, with automatic delete.
Station with truck stops.
Definition: station_type.h:56
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Definition of base types and functions in a cross-platform compatible way.
Select unload.
Definition: order_widget.h:27
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: order_gui.cpp:1081
NWID_SELECTION widget for middle part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:36
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:34
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1475
Always skip.
Definition: order_type.h:124
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Base of waypoints.
Geometry functions.
rectangle (stations, depots, ...)
Simple depressed panel.
Definition: widget_type.h:50
Order list panel.
Definition: order_widget.h:19
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
Definition: window.cpp:1053
VehicleOrderID OrderGetSel() const
Return the memorised selected order.
Definition: order_gui.cpp:525
void OrderHotkey_Transfer()
Handle the transfer hotkey.
Definition: order_gui.cpp:649
insert a new order
Definition: command_type.h:229
OrderPlaceObjectState
Under what reason are we using the PlaceObject functionality?
Definition: order_gui.cpp:476
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:317
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:310
uint16 GetRange() const
Get the range of this aircraft.
Definition: aircraft.h:135
Vehicle view; Window numbers:
Definition: window_type.h:334
Order window code for all vehicles.
Definition: order_gui.cpp:473
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:176
virtual void OnMouseDrag(Point pt, int widget)
An &#39;object&#39; is being dragged at the provided position, highlight the target if possible.
Definition: order_gui.cpp:1488
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: order_gui.cpp:1476
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Display &#39;stop sharing&#39; in the middle button of the bottom row of the vehicle order window...
Definition: order_gui.cpp:509
The tile has no ownership.
Definition: company_type.h:27
Vehicle timetable; Window numbers:
Definition: window_type.h:219
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
OrderConditionComparator
Comparator for the skip reasoning.
Definition: order_type.h:133
Baseclass for nested widgets.
Definition: widget_type.h:126
Button with a drop-down.
Definition: widget_type.h:82
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
Always go to the depot.
Definition: order_type.h:167
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
Definition: order_base.h:129
static const OrderConditionVariable _order_conditional_variable[]
Variables for conditional orders; this defines the order of appearance in the dropdown box...
Definition: order_gui.cpp:152
Skip current order.
Definition: order_widget.h:21
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: order_gui.cpp:1325
Basic functions/variables used all over the place.
Service the vehicle and then halt it.
Definition: order_type.h:110
StationFacilityByte facilities
The facilities that this station has.
Right offset of the text of the frame.
Definition: window_gui.h:73
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Road vehicle type.
Definition: vehicle_type.h:27
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:167
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
Service only if needed.
Definition: order_type.h:168
Left offset of the text of the frame.
Definition: window_gui.h:72
Station with a dock.
Definition: station_type.h:59
Display the conditional order buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:505
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:654
The value to set the condition to.
Definition: order_type.h:157
Skip based on the remaining lifetime.
Definition: order_type.h:125
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:54
NWID_SELECTION widget for left part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:35
Transfer all cargo onto the platform.
Definition: order_type.h:61
Ship vehicle type.
Definition: vehicle_type.h:28
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
Definition: order_base.h:131
VehicleOrderID GetOrderFromPt(int y)
Calculate the selected order.
Definition: order_gui.cpp:539
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:965
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: order_gui.cpp:799
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
Definition: order_base.h:150
Skip when the vehicle requires service.
Definition: order_type.h:123
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
OwnerByte owner
The owner of this station.
OrderUnloadFlags
Flags related to the unloading order.
Definition: order_type.h:58
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not)...
Definition: order_base.h:185
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1143
Open refit options.
Definition: order_widget.h:31
Display &#39;delete&#39; in the middle button of the bottom row of the vehicle order window.
Definition: order_gui.cpp:508
void OrderClick_FullLoad(int load_type)
Handle the click on the full load button.
Definition: order_gui.cpp:572
A conditional variable changes.
Definition: order_type.h:155
Functions related to companies.
default
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
OrderStopLocation
Where to stop the trains.
Definition: order_type.h:89
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3015
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:81
Goto destination.
Definition: order_widget.h:25
Passes an OrderNonStopFlags.
Definition: order_type.h:150
Automatic refitting is allowed.
Definition: engine_type.h:158
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: order_gui.cpp:1139
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:471
VehicleOrderID order_over
Order over which another order is dragged, INVALID_VEH_ORDER_ID if none.
Definition: order_gui.cpp:513
GUISettings gui
settings related to the GUI
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:92
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Toggle timetable view.
Definition: order_widget.h:18
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition: order_base.h:135
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OrderLoadFlags
Flags related to the loading order.
Definition: order_type.h:68
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: order_gui.cpp:1160
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
void OrderHotkey_NoLoad()
Handle the &#39;no loading&#39; hotkey.
Definition: order_gui.cpp:588
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:669
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:105
Send the vehicle to the nearest depot.
Definition: order_type.h:111
void Free()
&#39;Free&#39; the order
Definition: order_cmd.cpp:65
Vertical container.
Definition: widget_type.h:77
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
uint16 GetConditionValue() const
Get the value to base the skip on.
Definition: order_base.h:147
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Do not add shading to this text colour.
Definition: gfx_type.h:271
A tile of a station.
Definition: tile_type.h:48
Skip based on the amount of load.
Definition: order_type.h:119
void SetTimetableParams(int param1, int param2, Ticks ticks)
Set the timetable parameters in the format as described by the setting.
change the refit information of an order (for "goto depot" )
Definition: command_type.h:270
uint ConvertDisplaySpeedToSpeed(uint speed)
Convert the given display speed to the (internal) speed.
Definition: strings.cpp:737
Display &#39;load&#39; / &#39;unload&#39; / &#39;refit&#39; buttons in the top row of the ship/airplane order window...
Definition: order_gui.cpp:503
Station with train station.
Definition: station_type.h:55
Totally no unloading will be done.
Definition: order_type.h:62
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:80
Skip based on the maximum speed.
Definition: order_type.h:121
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2133
Vehicle details; Window numbers:
Definition: window_type.h:195
Display &#39;service&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:496
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:768
Passes an OrderLoadType.
Definition: order_type.h:153
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1084
Drop down list.
Definition: widget_type.h:70
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
Station with bus stops.
Definition: station_type.h:57
Order * GetOrder(int index) const
Returns order &#39;index&#39; of a vehicle or NULL when it doesn&#39;t exists.
Definition: vehicle_base.h:860
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:319
HighLightStyle
Highlighting draw styles.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:687
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:681
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:106
vehicle is accepted as target as well (bitmask)
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
virtual void OnPaint()
The window must be repainted.
Definition: order_gui.cpp:1071
Choose condition variable.
Definition: order_widget.h:32
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:17
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Select full load.
Definition: order_widget.h:26
Order list scrollbar.
Definition: order_widget.h:20
Choose condition value.
Definition: order_widget.h:34
uint32 Pack() const
Pack this order into a 32 bits integer, or actually only the type, flags and destination.
Definition: order_cmd.cpp:200
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:369
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:69
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1973
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3075
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
bool new_nonstop
ttdpatch compatible nonstop handling
Definition: settings_type.h:91
The passed event is handled.
Definition: window_type.h:714
Text is written right-to-left by default.
Definition: strings_type.h:26
Right align the text (must be a single bit).
Definition: gfx_func.h:100
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:663
Functions related to tile highlights.
Find a place automatically.
Definition: window_gui.h:156
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:60
static const NWidgetPart _nested_orders_train_widgets[]
Nested widget definition for "your" train orders.
Definition: order_gui.cpp:1534
Display an empty panel in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:499
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
This depot order is because of a regular order.
Definition: order_type.h:102
Go to the depot and stop there.
Definition: order_type.h:169
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1354
Base classes/functions for stations.
static Station * Get(size_t index)
Gets station with given index.
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
Get the order command a vehicle can do in a given tile.
Definition: order_gui.cpp:358
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:30
move an order
Definition: command_type.h:327
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Full load a single cargo of the consist.
Definition: order_type.h:71
This depot order is because of the servicing limit.
Definition: order_type.h:101
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:29
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
Skip if the variable is false.
Definition: order_type.h:141
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
Skip based on the maximum reliability.
Definition: order_type.h:126
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition: order_base.h:156
Station data structure.
Definition: station_base.h:446
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1240
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:133
Display &#39;refit&#39; in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:500
NWID_SELECTION widget for the top row of the &#39;your non-trains&#39; order window.
Definition: order_widget.h:39
modify an order (like set full-load)
Definition: command_type.h:226
Station with an airport.
Definition: station_type.h:58
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:833
delete an order
Definition: command_type.h:228
Choose condition type.
Definition: order_widget.h:33
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: order_gui.cpp:1424
Display &#39;unload&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:495
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition: order_cmd.cpp:77
OrderDepotTypeFlags
Reasons that could cause us to go to the depot.
Definition: order_type.h:99
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:406
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Definition: order_base.h:124
(Toggle) Button with text
Definition: widget_type.h:55
void OrderHotkey_NoUnload()
Handle the &#39;no unload&#39; hotkey.
Definition: order_gui.cpp:657
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
Train vehicle type.
Definition: vehicle_type.h:26
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
void OrderClick_Delete()
Handle the click on the delete button.
Definition: order_gui.cpp:701